i’m having a small problem here.
I’m using a simple rule to redirect all requests to a script, excepts some folders with static content :
RewriteEngine On
RewriteCond $1 !^(templates|css|js|uploads)/(.*)$
RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]
Most of the time, the redirection is good and transparent.
But if the folder matching the URL exists and if i don’t put the last “/”, i will have a 301 redirect.
Examples : (the folder gallery doesn’t exists but mods does)
- ht*p://localhost/test/gallery/ -> OK
- ht*p://localhost/test/mods/ -> OK
- htp://localhost/test/mods -> 301 redirection to htp://localhost/test/mods/?url=mods
I have this problem on all apache2 servers (tested Fedora, Debian, Windows).
Someone knows how to solve this ?
Thanks
This is due to the
DirectorySlashdirective, which will perform the external redirection after your rewrite is performed, which has the unintended consequence of taking your added query string with it.You can turn
DirectorySlashoff, but it’s not recommended for the reasons described in the documentation. The preferred option in this case is probably to just performmod_dir‘s work for it, redirecting to the appropriate slash-terminated URL before performing your rules. Something like this above your existing rule should work: