.htaccess block all ip's, if they are blocked redirect to a page

冷暖自知 提交于 2019-12-08 12:00:18

问题


So I am blocking all ip's except the ones on a list, so how can I redirect people to a new site if they're blocked?


回答1:


My assumption is that you are blocking ip's using allow/deny. I do not believe that you are able to specify a redirect rule to work on the denied ip's as you have told the server to reject their connections outright.

Instead you are going to want to use the RewriteEngine to do a redirect. In case you are unfamiliar with the syntax I have provided the following example which will redirect all ip's except for "72.14.204.99" and "72.14.204.100" to "example.org":

RewriteEngine on
RewriteCond %{REMOTE_ADDR} !^72\.14\.204\.99$
RewriteCond %{REMOTE_ADDR} !^72\.14\.204\.100$
RewriteRule ^ http://www.example.org/ [R]


来源:https://stackoverflow.com/questions/8348515/htaccess-block-all-ips-if-they-are-blocked-redirect-to-a-page

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!