Append a parameter to a querystring with mod_rewrite

Posted by Matt on Stack Overflow See other posts from Stack Overflow or by Matt
Published on 2011-02-03T15:00:24Z Indexed on 2011/02/03 15:25 UTC
Read the original article Hit count: 170

Filed under:
|
|
|
|

Hello,

I would like to use mod_rewrite to append a parameter to the end of a querystring. I understand that I can do this using the [QSA] flag.

However, I would like the parameter appended ONLY if it does not already exist in the querystring. So, if the querystring was:

http://www.mysite.com/script.php?colour=red&size=large

I would like the above URL to be re-directed to

http://www.mysite.com/script.php?colour=red&size=large&weight=heavy

Where weight=heavy is appended to the end of the querystring only if this specific parameter was not there in the first place! If the specific parameter is already in the URL then no redirect is required.

Can anybody please suggest code to put in my .htacess file that can do this? Thanks.

© Stack Overflow or respective owner

Related posts about php

Related posts about apache