1

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.

Nathan Osman
  • 2,725
  • 7
  • 32
  • 46

2 Answers2

1

This will happen if MultiViews is enabled (part of mod_negotiation). If MultiViews is enabled and you request /user, where /user.php exists as a physical file then mod_negotiation triggers an internal subrequest for users.php (it "searches" for an appropriate file that would return the correct mime-type).

You need to disable MultiViews in your .htaccess file:

Options -MultiViews

MultiViews is disabled by default on Apache, however, some shared hosts do enable this for some reason.

MrWhite
  • 12,647
  • 4
  • 29
  • 41
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.

Nathan Osman
  • 2,725
  • 7
  • 32
  • 46