Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Here is my rule:

RewriteRule ^user/(\d+)$ rewrite.php?id=$1

This redirects, but $_GET['id'] is not set. If I change the above rule to:

RewriteRule ^anything/(\d+)$ rewrite.php?id=$1

It works. Why does one work but not the other?

Here is more information:

  • There is no directory named user
  • The only other .htaccess file in the hierarchy is blank.
  • anything can be replaced by anything other than user.

Update: I checked the rewritelog and it's empty.

share|improve this question

1 Answer 1

I finally found the cause of the problem... Apparently (and this is documented nowhere that I could find) if you have a file (in this case, PHP) with the same name as the first virtual directory the rewrite rule doesn't work. (Redirect loops, missing parameters, etc.)

For example, the following rule:

#RewriteRule ^user/(\d+)$ user.php?id=$1 [L]

Will malfunction if there is a file named user.php in the same directory as the PHP file.

share|improve this answer
    
You probably have activated mod_speling (httpd.apache.org/docs/2.2/mod/mod_speling.html) in your Apache httpd configuration which causes this effect. –  joschi May 9 '10 at 5:59
    
Nope. A quick check shows that mod_speling is disabled. –  Nathan Osman May 9 '10 at 6:25
1  
Disable MultiViews. –  Mo. May 9 '10 at 11:40

Your Answer

 
discard

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.