I'm using mod_rewrite to rewrite all non-existing files/directory's to
my index.php. That's easy. But this time i also want it to perform a
rewrite on some existing directory's.
Here's what i have now:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d [OR]
RewriteCond %{REQUEST_FILENAME} /(admin|pages)
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
As you see I'm also rewriting when they try to access the admin or
pages directory (2 directory's that actually exist)
When i open www.site.com/admin/test/blabla/ the query parameter q gets
set correctly to "/admin/test/blabla/".
However when i open www.site.com/admin (with no ending / ) apache
redirects me to "www.site.com/admin/?q=admin"
Why is
Found the solution to this "weird behavior".
I just found out that the redirect is performed by apache itself, not
mod_rewrite.
Basically if you try to access a directory without a tailing / it adds
one by itself.
So what i did to solve my problem is right before rewriting to
index.php?q=....
just check if it's a directory and if it has a tailing /. If it
doens't add one myself.
Like this:
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_FILENAME} !^.*/$
RewriteRule ^(.*)$ $1/ [L,QSA]