Forum Moderators: phranque

Message Too Old, No Replies

Changing query string with mod rewrite

         

marciano

4:07 pm on Jan 29, 2011 (gmt 0)

10+ Year Member



Hello,
I am asking for some help on how to rewrite this
[mysite.com...] to [mysite.com...]

The variable "a" is renamed to "id" and its value "v1" is dynamic
The rest of the query string will be suppressed.

My approach is
RewriteCond %{QUERY_STRING} ^a=(.+)
RewriteRule ^script\.php$ newscript.php?id=%1 [R=301,L]

(.+) contents all query string after "a=" and the resulting query string is the same as the old one but "id" instead "a" as expected.
How to keep ony the first var?
Thank you n advance

marciano

10:58 pm on Jan 29, 2011 (gmt 0)

10+ Year Member



Here's the solution [forums.devshed.com...]

jdMorgan

2:10 am on Feb 1, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just use a more-specific pattern for the query string, stopping the match-capture after the value for "a" :

RewriteCond %{QUERY_STRING} ^a=([^&]+)
RewriteRule ^script\.php$ newscript.php?id=%1 [R=301,L]

Jim