Max Hodges Max Hodges - 8 months ago 47
Apache Configuration Question

mod_rewrite to change query string parameter name

I need help writing a mod rewrite rule to change the name of a query string parameter. I want to change the name, not the value.

old name


new name

so a link like this

will become

I found this article but the accepted answer generated errors for the OP:
mod_rewrite - old parameter name to new name

also this article, but the solution was to use PHP. which will not work in my case:
APACHE mod_rewrite change variable name in query string

I can't use PHP because some affiliate tracking code creates a cookie from the query string--and expects the a_aid. So I'm trying to convert
for it


OK think I hacked it together on my own. Please post an answer if you think its brittle or could be done better and I'll accept yours instead

RewriteCond %{QUERY_STRING} ^(.*)partner(.*)$
RewriteRule ^(.*)$ $1?%1a_aid%2 [R=301,L]