[英]Rewriting a variable in a querystring with .htaccess
I use a PHP script with my site that produces a querystring in the URL. 我在我的网站上使用PHP脚本,在URL中生成查询字符串。 One of the variables in the querystring is:
colour=red
查询字符串中的一个变量是:
colour=red
I would like to make a rule in my .htaccess file that re-writes all instances of colour=red
to colour=blue
. 我想在我的.htaccess文件中制定一条规则,将所有
colour=red
实例重写为colour=blue
。
I don't have access to change the original PHP script so a .htaccess rule is needed. 我无权更改原始PHP脚本,因此需要.htaccess规则。
RewriteEngine On
RewriteCond %{QUERY_STRING} ^(.*&|)colour=red(&.*|)$ # search colour=red
RewriteRule ^(.*)$ $1?%1colour=blue%2 [L,R=301] # redirect to colour=blue
This will redirect URLs with colour=red
in query-string to URLs with colour=blue
这会将查询字符串中
colour=red
网址重定向到colour=blue
网址
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.