1

I couldn't think of a good title for this, it's hard to explain. Basically, I have mod_rewrite setup on my server. It turns each ?a=1&b=2&c=3 etc into /1/2/3/

I want to implement a feature where I can do something like this: /login/?return_url=/home/ The return_url would change depending on where the user was last. I know there are other methods of finding out the return url, but I would like to keep it in the URL.

My issue is that the following does not work: /login/?return_url=/home/

However, /login.php?return_url=/home/ does work.

Why can't PHP see the return_url variable in the first (preferred) situation?

Here's my current code:

RewriteRule ^(.*)/(.*)/(.*)/([A-Za-z0-9_-]+)/$ /?a=$1&b=$2&c=$3&d=$4 [L]
RewriteRule ^(.*)/(.*)/([A-Za-z0-9_-]+)/$ /?a=$1&b=$2&c=$3 [L]
RewriteRule ^(.*)/([A-Za-z0-9_-]+)/$ /?a=$1&b=$2 [L]
RewriteRule ^([A-Za-z0-9_-]+)/$ /?a=$1 [L]
Jack
  • 203
  • 1
  • 4
  • 9
  • 1
    maybe you'll get more chances to have an answer if you show us the mod_rewrite rules youhave, don't you think? – regilero Jul 25 '11 at 10:59

1 Answers1

4

The QSA directive is probably what you're looking for:

'qsappend|QSA' (query string append)
This flag forces the rewrite engine to append a query string part of the substitution string to the existing string, instead of replacing it. Use this when you want to add more data to the query string via a rewrite rule.

E.g.,

RewriteRule ^something/([0-9]+)$ something.php?id=$1 [QSA]

Will let something/9?key=val go to something.php?id=9&key=val

jensgram
  • 31,109
  • 6
  • 81
  • 98
  • Thanks for the link. I'm a bit of a newb at all this >.< I'm not entirely sure how to add that flag. Do I put it next to the [L]. ie: [L|QSA] ? – Jack Jul 25 '11 at 10:58
  • @Jack delimit with a comma (`,`), not a pipe (`|`): `[L,QSA]` – jensgram Jul 25 '11 at 10:59
  • Thanks, it saved me a lot of hassle, because I was going to manually parse the `$_SERVER['REQUEST_URI']`... – Pateman Mar 08 '12 at 19:48