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

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

我需要帮助编写 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为了它

最佳答案

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

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

关于apache - mod_rewrite 更改查询字符串参数名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15005384/

相关文章:

apache - Angular CLI 路由 - 不适用于(Apache-)服务器

regex - .htaccess - 强制 url 从 'dir/page.html' → 'dir/page'

android - 原因 : com. android.dex.DexException : Multiple dex files define Lorg/apache/commons/io/IOCase in Studio 3. 0

php - htaccess 检查查询字符串是否为空

.htaccess - 我可以使用 .htaccess 规则对网站使用通配符,然后重写特定页面吗?

regex - 无法为 Mod Rewrite/URLRewriteFilter 构建正确的正则表达式。我如何否定一个范围?

IIS URL 重写 - 操作 URL 中的多个条件反向引用

c# - 最好用的 URL 重写器是什么?

apache - 内容安全策略无效命令

wordpress - 域仅作为 https (wordpress)