在htaccess的查询字符串重写一个变量 [英] Rewriting a variable in a querystring with .htaccess
本文介绍了在htaccess的查询字符串重写一个变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用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
这篇关于在htaccess的查询字符串重写一个变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文