mod_rewrite 更改查询字符串参数名称 [英] mod_rewrite to change query string parameter name

查看:32
本文介绍了mod_rewrite 更改查询字符串参数名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助编写 mod 重写规则来更改查询字符串参数的名称.我想更改名称,而不是值.

旧名称 合作伙伴新名称a_aid

这样的链接

http://domain.com/?partner=derphipster&pname=foo&plink=http%3A%2F%2Fbar.com%2Ffoo

会变成

http://domain.com/?a_aid=derphipster&pname=foo&plink=http%3A%2F%2Fbar.com%2Ffoo

我找到了这篇文章,但接受的答案为 OP 生成了错误:mod_rewrite - 旧参数名称到新名称

也是这篇文章,但解决方案是使用PHP.这在我的情况下不起作用:APACHE mod_rewrite 更改查询字符串中的变量名称

我无法使用 PHP,因为某些附属跟踪代码从查询字符串创建了一个 cookie——并且需要 a_aid.所以我正在尝试将 partner 转换为 a_aid

解决方案

好吧,我想我是自己把它混在一起的.如果您认为它脆弱或可以做得更好,请发布答案,我会接受您的答案

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

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

解决方案

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]

这篇关于mod_rewrite 更改查询字符串参数名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆