Žan Kusterle
Žan Kusterle

Reputation: 570

Rewriting URL that contains question mark

I am encountering a problem regarding URL rewriting. I am using Apache's mod rewrite to rewrite URLs. For example, I rewrite URL

Then I show specific response for this URL. Right now my rewrite rule looks like this:

RewriteRule ^([a-z_/\?]+)$ request.php?string=$1

But the problem begins if I have URL www.website.com/some/data/?id=12&name=John and rewrite it, I get something like this: request.php?string=some/data/?id=12&name=John. It seems that in this example another question mark confuses PHP. If I try to retrieve $_GET['string'] in request.php all I get is: some/data/.

For further reference, Gmail does something similar with it's URL:
https://mail.google.com/mail/?ui=1&shva=1

Upvotes: 1

Views: 964

Answers (1)

hakre
hakre

Reputation: 197757

I suggest (as mario) to take a look into the QSA flag (Query String Append). Additionally I would take the question-mark out of the character class in the regex:

RewriteRule ^([a-z_/]+)$ request.php?string=$1 [L,QSA]

Upvotes: 5

Related Questions