【问题标题】:mod_rewrite to change query string parameter namemod_rewrite 更改查询字符串参数名称
【发布时间】:2013-02-06 23:04:26
【问题描述】:

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

旧名称partner 新名字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 - old parameter name to new name

也是这篇文章,但解决方案是使用 PHP。这在我的情况下不起作用: APACHE mod_rewrite change variable name in query string

我不能使用 PHP,因为一些附属跟踪代码会根据查询字符串创建一个 cookie,并且需要 a_aid。所以我正在尝试将partner 转换为a_aid

【问题讨论】:

    标签: apache mod-rewrite url-rewriting query-string querystringparameter


    【解决方案1】:

    好吧,我想我是自己破解的。如果您认为它很脆弱或可以做得更好,请发布答案,我会接受您的答案

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

    【讨论】:

      猜你喜欢
      • 2014-01-28
      • 1970-01-01
      • 2011-07-23
      • 1970-01-01
      • 2016-11-02
      • 2013-08-03
      • 1970-01-01
      • 2015-06-09
      • 2012-08-30
      相关资源
      最近更新 更多