Forum Moderators: phranque

Message Too Old, No Replies

Redirect (not Rewrite) keeping Query String

A Redirect seems to keep the query_string, but should I use Rewrite instead

         

my_planet

11:53 am on Aug 14, 2007 (gmt 0)

10+ Year Member



A very simple one:

I want to redirect /a to /b making sure any query strings which were passed to /a get passed on to /b.

This works fine with a simple test, but I can't feeling like I should be using mod_rewrite to do this.

Any comments much appreciated.

vincevincevince

11:56 am on Aug 14, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



With mod_rewrite [httpd.apache.org] you should be using [QSA] after your rule (Query String Append)

my_planet

12:00 pm on Aug 14, 2007 (gmt 0)

10+ Year Member



Well, not really. See: [webmasterworld.com...]

QSA should only really be used if you adding stuff to the query string

vincevincevince

12:52 pm on Aug 14, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



my_planet, you use QSA if you want to redirect:
a.php?var=123 --> b.php?x=2&var=123
Or at least, that's how it has worked for me.

You are entirely right, that if you are doing basically a file-name swap, then it shouldn't be needed. Good point.

jdMorgan

1:25 pm on Aug 14, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



And note the implication in the original post that mod_rewrite was not used -- So it's likely that the Redirect or RedirectMatch directives of mod_alias were used, and that they too passed the query strings unchanged.

In these cases, I apply a simple procedural policy: Test the heck out of the new code, and if it works, it works. Then make a note on your copy of the Apache documentation for that directive, so that you can answer similar questions (for yourself or for others) in the future. :)

Jim

my_planet

1:46 pm on Aug 14, 2007 (gmt 0)

10+ Year Member



Thankyou jdMorgan. Yes, I wish to use the Redirect directive.

So, you're saying that "Redirect" by default passes the query string along without changing it?

Can anyone point me towards any kind of reference to this behaviour, because I can't seem to find any anywhere. Thanks again guys.

jdMorgan

2:01 pm on Aug 14, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No I'm saying that if mod_alias directives pass the query strings for you, then I'll write that down as a note in my copy of the documentation, because although it should do so, this behaviour is not documented.

I've never tried it myself, but if it didn't work like that, then much of the Web would be broken, as mod_alias directives are often used to redirect entire domains -- including those of query-driven sites. However,...

Trust your own testing. Only.

Jim

my_planet

3:27 pm on Aug 14, 2007 (gmt 0)

10+ Year Member



Yep, query string is getting passed on just fine. Thanks Jim.