tags:

views:

30

answers:

1

Hi, I'm trying to make

site.com/link?p=2

give $_GET['p']==2 even though i've already made

site.com/link

rewrite to

site.com/index.php?page=link

So, i'm trying to replace site.com/link?p=2 with site.com/link&p=2

RewriteEngine on

RewriteRule (.*)\?(.*) $1\&$2

RewriteCond %{REQUEST_URI} !\....$
RewriteRule ^(.*)$ /index.php?p=$1

It doesn't work!

+3  A: 

RewriteRule cannot see query strings (the ? and anything after it) on the left-hand side; it matches only on the path part of the URL.

But the good news is, all you probably need to do is this:

RewriteEngine on

RewriteCond %{REQUEST_URI} !\....$
RewriteRule ^(.*)$ /index.php?p=$1 [QSA]

The QSA option, Query String Add, tells your RewriteRule to add to the query string instead of replacing it (the default behavior, which doubtless prompted the whole issue).

chaos
Thanks! Do you know why it's so?
Not definitively, but I would guess that the designers of `mod_rewrite` felt that, on the one hand, it was already mind-bogglingly complex enough without the arcanities that rewriting query strings would introduce, and that on the other hand, it's really hardly necessary to rewrite query strings, since they can be reinterpreted at will by the scripts that receive them anyway.
chaos