Unwanted mod_rewrite behavior
I just did a fresh install of the lamp stack on ubuntu and enabled the mod_rewrite module for my default site. What I want is similar to drupal queries where the entire query string is stored in one variable. You can use the following mod_rewrite code to do this:
RewriteRule ^(.*)$ home.php?q=$1 [L,QSA]
The problem starts when some line starts with a filename that already exists in the directory; For example, if I open the page: http://localhost/home/blablabla
- the content of $ _GET looks like this:
Array ( [q] => home.php )
What I want to see:
Array ( [q] => home/blablabla )
I think this is something with the standard site or mod_rewrite config, but I just couldn't figure it out ...
a source to share
You must exclude home.php
:
RewriteCond %{REQUEST_URI} !^/home\.php$
RewriteRule ^(.*)$ home.php?q=$1 [L,QSA]
Or you exclude all existing files:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ home.php?q=$1 [L,QSA]
Reason: The flag L
causes an internal redirect with the new rewritten URL. And the new URL home.php
matches the expression as well ^(.*)$
.
a source to share