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 ...

0


a source to share


3 answers


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 ^(.*)$

.

+2


a source


Not really the answer to your question, but isn't that what _SERVER ["REQUEST_URI"] and _SERVER ["REDIRECT_URL"] are for?



0


a source


Looks like you might need the newly added [DPI] flag to remove PATH_INFO with multiple rewritable directories.

0


a source







All Articles