Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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'm trying to do something incredibly simple: If the user requests the home page,, then stop all rules and serve the file normally. If anything else in the world is requested, silently redirect to a php script.

I'm using this:

RewriteCond %{REQUEST_URI} !^/$ [NC]
RewriteRule .* /000_ROUTE.php [L]

It seems that my condition is being ignored and the home page is redirecting too.

How can I make this work?

share|improve this question
Turn on rewrite debugging and paste results if the answer isn't obvious from there. – womble Dec 23 '09 at 2:05
up vote 1 down vote accepted

If the rule is used in a .htaccess file, use

RewriteCond %{REQUEST_URI} !^/000_ROUTE.php$
RewriteRule . /000_ROUTE.php [L]

If it's in your VirtualHost-block or main config file instead, use

RewriteCond %{REQUEST_URI} !^/000_ROUTE.php$
RewriteRule /. /000_ROUTE.php [L]

(the only difference is the leading slash on the RewriteRule).

The first thing Apache httpd does before evaluating the RewriteConds is to evaluate the RewriteRule. Putting the condition into the Rule (and in this case the condition is that there is at least one character after the slash) saves Apache having to evaluate the RewriteCond entirely for requests at "/". The RewriteCond ensures that you don't end up in a loop of rewrites -- after all, 000_ROUTE.php is not "/", either.)

Depending on how often that rule will get hit (i.e. if you expect it to get hit a lot and thus separating out a RewriteCond is just going to add overhead), you could also condense it into

RewriteRule ^(?!000_ROUTE.php). /000_ROUTE.php [R,L]

for .htaccess or -contexts

RewriteRule ^/(?!000_ROUTE.php). /000_ROUTE.php [R,L]

for or server-contexts.

share|improve this answer

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.