Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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

<virtualhost *:80>
    DocumentRoot /var/www/

<virtualhost *:80>
    VirtualDocumentRoot /var/www/
    ServerAlias *

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

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

Finaly it works fine for requests like, but not for

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/
[debug] core.c(3118): redirected from r->uri = /var/www/
[debug] core.c(3118): redirected from r->uri = /foo

So how can I fix that and what is wrong?

share|improve this question
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. – Krist van Besien 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? – woo Apr 23 '13 at 9:29
No, NS doesn't really block them in this case. – Krist van Besien Apr 26 '13 at 4:26
up vote 3 down vote accepted

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:

<virtualhost *:80>
    VirtualDocumentRoot /var/www/
    ServerAlias *
    FallBackResource /index.php
share|improve this answer
The main idea was to implement ‘pretty urls’ and allow developers to tune webserver's settings without granting them access to whole server config. – woo Apr 23 '13 at 9:11

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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