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

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

问题描述

我需要帮助写一模重写规则更改查询字符串参数的名称。我想改名字,而不是价值。

老字号合作伙伴
新的名称 a_aid

所以像这样的链接

<$p$p><$c$c>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的错误:
<一href=\"http://stackoverflow.com/questions/569600/mod-rewrite-old-parameter-name-to-new-name\">mod_rewrite - 旧参数名称以新名称

也这篇文章,但解决方案是使用PHP。这将不是在我的情况下工作:
<一href=\"http://stackoverflow.com/questions/5451183/apache-mod-rewrite-change-variable-name-in-query-string\">APACHE在mod_rewrite的查询字符串修改变量名

并期望a_aid -

由于某些子公司跟踪code从查询字符串创建一个cookie,我不能使用PHP。所以我想转换合作伙伴 a_aid


解决方案

确定想我砍死在一起我自己。如果你认为它的脆性请张贴一个答案或者可以做得更好,我会接受你,而不是

 的RewriteCond%{QUERY_STRING} ^(。*)的合伙人(。*)$
重写规则^(。*)$ $ 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天全站免登陆