views:

91

answers:

3

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

A: 

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

VolkerK
+2  A: 

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

Gumbo
Excluding the existing files (and directories) by using the command above is pretty handy, however, in this case the $_GET shows up as empty...
turezky
MultiViews could cause this bahavior. Try to disabled it. See http://httpd.apache.org/docs/2.2/content-negotiation.html#multiviews
Gumbo
Yeap, it is :) Disabling right away :)
turezky
A: 

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

covener