mod_Rewrite:按IP过滤特定页面并重定向它们 [英] mod_Rewrite: Filter specific pages by IP and redirect them

查看:187
本文介绍了mod_Rewrite:按IP过滤特定页面并重定向它们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一种通过IP过滤特定页面的方法,并将它们重定向到另一个页面。

I am researching a way to work filtering specific pages by IP and redirect them on a different page.

下面的代码无效。

RewriteCond %{REMOTE_ADDR} ^/192.168.10.*
RewriteCond %{REQUEST_URI} ^/support
RewriteRule ^/.* http://www.yahoo.com/gone [R,NE]

一次已访问 http://example.com/support 链接,它们位于192.168.10上。 *阻止,它必须转到yahoo.com示例页面。

Once the link http://example.com/support has been accessed and they're on the 192.168.10.* block, it must go to the yahoo.com example page.

但是,就像我说的那样。它什么也没做。任何想法为什么它不能正常工作?

But, like I said. It just did nothing. Any ideas why it did not work correctly?

推荐答案

正如yoda在评论中所说,不要放 / 在ip地址前面。另外,模式中的应该是 \。,因为这是一个perl兼容的正则表达式。您还可以在请求uri匹配中添加 [NC] ,无案例(敏感)。最后,您可以将第二个条件与 RewriteRule 合并。总之:

as yoda says in the comment, don't put a / in front of the ip address. also, the . in the pattern should be \., as this is a perl compatible regular expression. you could also add a [NC], no case (sensitive), to the request uri match. finally, you could merge the second condition with the RewriteRule. all together:

RewriteCond %{REMOTE_ADDR} ^192\.168\.10\..*
RewriteRule ^/support http://www.yahoo.com/gone [R,NE,NC]

这篇关于mod_Rewrite:按IP过滤特定页面并重定向它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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