且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

只允许某些IP地址使用mod_rewrite访问网站?

更新时间:2023-12-02 16:01:10

忘记发布答案。最后只是一个错字.. DOH!

Forgot to post the answer to this. It was just a typo in the end.. DOH!

如果你注意到,一些%{REMOTE_ADDR}行有大括号,有些行有正常括号!它们都需要卷曲的。

If you notice, some of the %{REMOTE_ADDR} lines have curly brackets, and some have normal brackets! They all needed curly ones.

RewriteEngine on
RewriteCond %{REMOTE_ADDR} !^123\.123\.123\.123
RewriteCond %{REMOTE_ADDR} !^124\.124\.124\.124
RewriteCond %{REMOTE_ADDR} !^125\.125\.125\.125
RewriteCond %{REMOTE_ADDR} !^126\.126\.126\.126
RewriteCond %{REMOTE_ADDR} !^127\.127\.127\.127
RewriteCond %{REMOTE_ADDR} !^128\.128\.128\.128

RewriteCond %{HTTP_REFERER} !^http://www\.example\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^http://example\.com/ [NC]

RewriteRule ^.*$ http://www.example.com [R=301,L]