Strange behavior with mod_rewrite
I am trying to perform this type of rewrite
http://sitename/foo/var1/var2 -> http://sitename/foo/index.php?/var1/var2
This is my .htaccess file(placed in the directory foo):
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L]
In my php script I am displaying the values of $_SERVER['REDIRECT_QUERY_STRING']
and $_SERVER['REQUEST_URI']
If I request a URL like http://sitename/foo/bar
the values as expected are bar
and /foo/bar
respectively.
This also works as expected for: http://sitename/foo/admin
and http://localhost/foo/bar
.
However when I try to access http://localhost/foo/admin
(using localhost instea开发者_如何转开发d of sitename) the REQUEST_URI changes to /admin/?admin
(this is how it displays in the address bar too, i.e http://localhost/foo/admin/?admin
)
I searched for any .htaccess files that might be conflicting and also turned on mod_rewrite logging at level 6 but was unable to find any info.
I have no clue what might be causing it. It would be great if I could know what might be causing this, otherwise I might switch to nginx.
Thanks all for replies. This was some weird server configuration error, things seem to be fine on the new VM I installed. @Dan Grossman , thanks for your suggestion about using $_GET, some of my code is simpler than earlier.
精彩评论