0

I want to set up robust multiuser development environment with apache2.

So I placeed the following file to etc/apache2/sites-available/mydomain.com

<virtualhost *:80>
    ServerName  mydomain.com
    ServerAlias www.mydomain.com
    DocumentRoot /var/www/mydomain.com/prod
</virtualhost>

<virtualhost *:80>
    VirtualDocumentRoot /var/www/mydomain.com/%1
    ServerName dev.mydomain.com
    ServerAlias *.dev.mydomain.com
</virtualhost>

And the following .htaccess file is copied to each /var/www/mydomain.com/* directory:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L,NS]

Finaly it works fine for requests like http://mydomain.com/, but not for http://mydomain.com/foo.

Request exceeded the limit of 10 internal redirects due to probable configuration error.
Use 'LimitInternalRecursion' to increase the limit if necessary.
Use 'LogLevel debug' to get a backtrace.
[debug] core.c(3112): r->uri = /var/www/mydomain.com/foo/index.php
…
[debug] core.c(3118): redirected from r->uri = /var/www/mydomain.com/foo/index.php
[debug] core.c(3118): redirected from r->uri = /foo

So how can I fix that and what is wrong?

3
  • Is there an index.php in every subdirectory? You are rewriting eveything that doesn't exist to index.php. So if you request a directory where there is no index.php it will keep rewriting it to index.php... Remember that every rewriterule in .htaccess will result in an internal subrequest, which will process all the rules again. Since you have access to your config file start by not using .htaccess files. There is no reason whatsoever for you to do this in this case. Apr 23 '13 at 4:49
  • @krist-van-besien ‘Remember that every rewriterule in .htaccess will result in an internal subrequest’ But NS flag blocks all subrequests, doesn't it?
    – wersoo
    Apr 23 '13 at 9:29
  • No, NS doesn't really block them in this case. Apr 26 '13 at 4:26
3

A common misconception is that rewriterules belong in .htaccess files. They don't. Actually putting rewriterules there is a bad idea.

You have access to your server config. You should put your rules there (if you choose touse any...)

However, there is a better solution for the "redirect everything not found to index.php". And this is to use fallbackresource:

http://httpd.apache.org/docs/2.2/mod/mod_dir.html#fallbackresource

<virtualhost *:80>
    VirtualDocumentRoot /var/www/mydomain.com/%1
    ServerName dev.mydomain.com
    ServerAlias *.dev.mydomain.com
    FallBackResource /index.php
</virtualhost>
1
  • The main idea was to implement ‘pretty urls’ and allow developers to tune webserver's settings without granting them access to whole server config.
    – wersoo
    Apr 23 '13 at 9:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.