mod_Rewrite: Filter specific pages by IP and redir

2019-05-29 01:56发布

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

The code below, did not work properly.

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

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?

1条回答
ゆ 、 Hurt°
2楼-- · 2019-05-29 02:30

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]
查看更多
登录 后发表回答