我使用PHP脚本我的网站产生一个查询字符串在URL中。一位在查询字符串变量是:颜色=红色
我想使我的.htaccess文件中的规则重新写颜色=红色
的所有实例颜色=蓝色
。
我没有机会改变原有的PHP脚本这样一个的.htaccess规则是必要的。
解决方案 RewriteEngine叙述上
的RewriteCond%{QUERY_STRING} ^(*放大器; |)颜色=红色(安培; * |)$#搜索颜色=红色
重写规则^(。*)$ $ 1〜%1colour =蓝%2 [L,R = 301]#重定向到颜色=蓝色
这将重定向与颜色=红色
的查询字符串的URL网址与颜色=蓝色
I use a PHP script with my site that produces a querystring in the URL. One of the variables in the querystring is: colour=red
I would like to make a rule in my .htaccess file that re-writes all instances of colour=red
to colour=blue
.
I don't have access to change the original PHP script so a .htaccess rule is needed.
解决方案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