[英]Mod Rewrite Appending Query String Parameters, Not Replacing
I am trying to generate an external redirect that involves a few specific tasks. 我正在尝试生成涉及一些特定任务的外部重定向。
Example: I have the url http://foobar.com/?a=123&b=456&c=blah 示例:我的网址为http://foobar.com/?a=123&b=456&c=blah
First, if parameter c = blah
, redirect to http://barfoo.com/ 首先,如果参数c =
blah
,则重定向到http://barfoo.com/
Second, replace a
with x
parameter so the final URL is http://barfoo.com/?x=123&b=456&c=blah 其次,用
x
参数替换a
,使最终URL为http://barfoo.com/?x=123&b=456&c=blah
Below is my best guess so far after researching on http://mod-rewrite-cheatsheet.com/ and Hidden features of mod_rewrite 在研究了http://mod-rewrite-cheatsheet.com/和mod_rewrite的隐藏功能之后,这是我迄今为止的最佳猜测
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.foobar\.com$ [NC]
RewriteCond %{QUERY_STRING} ^a=(.*)&b=(.*)&c=blah$ [NC]
RewriteRule ^(.*)$ http://barfoo.com/?x=%1&b=%2&c=blah [NC,L,QSA,R=301]
However, the URL is appending the query string, not replacing. 但是,URL追加了查询字符串,而不是替换。
I get redirected to http://barfoo.com/?x=123&b=456&c=blah&a=123&b=456&c=blah
我被重定向到
http://barfoo.com/?x=123&b=456&c=blah&a=123&b=456&c=blah
smacks forehead 打ack的额头
Removing QSA
from the flags solved the issue. 从标志中删除
QSA
解决了该问题。 QSA
means "append the existing query string to the current rewrite rule." QSA
意思是“将现有查询字符串追加到当前重写规则中”。 It ignores whatever new query string parameters you are adding. 它忽略您要添加的任何新查询字符串参数。
I thought it was needed to have query string parameters exist for the rewrite rule itself. 我认为需要为重写规则本身提供查询字符串参数。
RewriteRule ^(.*)$ http://barfoo.com/?x=%1&b=%2&c=blah [NC,L,R=301]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.