turezky
turezky

Reputation: 856

Unwanted mod_rewrite behaviour

I just did a fresh install of lamp stack on ubuntu and enabled the mod_rewrite module for my default website. What I want is something similar to the drupal's queries, when the whole query string is kept in one variable. For this purposes the following mod_rewrite code may be used:

RewriteRule ^(.*)$ home.php?q=$1 [L,QSA]

The problem begins when some a string starts with the name of the file already existing in the directory; For example if I open a page: http://localhost/home/blablabla - the contents of $_GET are as follows:

Array ( [q] => home.php ) 

What I want to see is:

Array ( [q] => home/blablabla ) 

I think it's something with default website or mod_rewrite configuration, but I just couldn't figure it out...

Upvotes: 0

Views: 233

Answers (3)

covener
covener

Reputation: 17871

Looks like you might need the recently added [DPI] flag to discard PATH_INFO with multiple per-directory rewrites.

Upvotes: 0

Gumbo
Gumbo

Reputation: 655319

You have to exclude the home.php:

RewriteCond %{REQUEST_URI} !^/home\.php$
RewriteRule ^(.*)$ home.php?q=$1 [L,QSA]

Or you exclude every existing file:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ home.php?q=$1 [L,QSA]

The reason: The L flag causes an internal redirect with the new rewritten URL. And the new URL home.php is also matched by the expression ^(.*)$.

Upvotes: 2

VolkerK
VolkerK

Reputation: 96159

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

Upvotes: 0

Related Questions