I use WampServer
(Apache/PHP/MySQL) and I have the following files in my www
directory:
www
[dir]
test
[dir]index.php
[file].htaccess
[file]I want to pass all URI requests as a parameter to index.php
without causing any external redirects (location changes in client browser). So I tried to use the following rule:
RewriteRule ^(.*)$ index.php?path=$1 [nocase,qsappend,end]
Which works quite good, except when the URI is /test
, in which case an external redirect changes the location to:
/test/?path=test
How can I make sure the external redirect does NOT happen even if the directory of the same name as the URI exists?
Expected result:
/test
index.php?path=test
Actual result:
/test
index.php?path=test
/test/?path=test
The ideal solution would be universal and would not apply only to test
directory, but to any directory.
Ok the problem seems to be a conflict between mod_rewrite
and mod_dir
. Possible solutions are:
mod_dir
<IfModule mod_dir.c>
DirectorySlash Off
</IfModule>
For more details about how mod_rewrite
and mod_dir
interact, this answer has some excellent info. And why the external redirect is necessary is explained in docs (Trailing Slash Problem).
Related links