简体   繁体   English

mod_rewrite更改查询字符串参数名称

[英]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. 我需要帮助编写mod重写规则来更改查询字符串参数的名称。 I want to change the name, not the value. 我想更改名称,而不是值。

old name partner new name a_aid 旧名partner新名称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 我发现这篇文章但是接受的答案为OP: mod_rewrite - 旧参数名称生成了新名称的错误

also this article, but the solution was to use PHP. 也是这篇文章,但解决方案是使用PHP。 which will not work in my case: APACHE mod_rewrite change variable name in query string 这在我的情况下不起作用: APACHE mod_rewrite更改查询字符串中的变量名称

I can't use PHP because some affiliate tracking code creates a cookie from the query string--and expects the a_aid. 我不能使用PHP,因为一些联盟会员跟踪代码从查询字符串创建一个cookie - 并期望a_aid。 So I'm trying to convert partner into a_aid for it 所以我正在尝试将partner转换为a_aid

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]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM