使用Apache的mod-rewrite如何根据查询字符串重定向? [英] Using Apache's mod rewrite how to redirect depending the query string?

查看:202
本文介绍了使用Apache的mod-rewrite如何根据查询字符串重定向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用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).

推荐答案

的Apache的手动讨论mod_rewrite的:

如果你想匹配的
  主机名,端口或查询字符串,可以使用
  与%{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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆