问题
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 partner
new name a_aid
so a link like this
http://domain.com/?partner=derphipster&pname=foo&plink=http%3A%2F%2Fbar.com%2Ffoo
will become
http://domain.com/?a_aid=derphipster&pname=foo&plink=http%3A%2F%2Fbar.com%2Ffoo
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 partner
into a_aid
for it
回答1:
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]
来源:https://stackoverflow.com/questions/15005384/mod-rewrite-to-change-query-string-parameter-name