使用Apache的mod-rewrite如何根据查询字符串重定向? [英] Using Apache's mod rewrite how to redirect depending the query string?
问题描述
使用Apache的mod-rewrite如何重定向 foo.php?R =确定
到 boo.php
(即根据查询字符串:如果研究
= 确定
然后重定向)
Using Apache's mod rewrite how to redirect foo.php?r=ok
to boo.php
(that is, depending the query string: if r
= ok
then redirect).
推荐答案
如果你想匹配的
主机名,端口或查询字符串,可以使用
与%{HTTP_HOST}的RewriteCond,
%{SERVER_PORT}或{%} QUERY_STRING
变量分别为
If you wish to match against the hostname, port, or query string, use a RewriteCond with the %{HTTP_HOST}, %{SERVER_PORT}, or %{QUERY_STRING} variables respectively.
在仔细一看的RewriteRules 和 RewriteConditions
编辑:新增工作示例
正则表达式使用写这些只是纯粹的天堂< /嘲讽>
The RegEx use to write these is just pure heaven </sarcasm>
任何如何...这里有一个简单的规则(Apache2的,的Mac OS X 10.5.8)
Any how... here's a simple rule (Apache2, Mac OS X 10.5.8)
RewriteCond $1 ^(foo\.php)
RewriteCond %{QUERY_STRING} (r=ok)
RewriteRule (foo\.php) /bar.php [R]
我测试这对于我能想到的(即R = KO,oof.php,foo.php?R = O),因为许多明显的警告,但未能打破它。
I tested this for as many obvious caveats that I could think of (ie r=ko, oof.php, foo.php?r=o), but couldn't break it.
这篇关于使用Apache的mod-rewrite如何根据查询字符串重定向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!