.htaccess重定向所有非特定IP地址的访问者多个IP

时间:2013-12-19 13:17:43

标签: regex apache .htaccess mod-rewrite

我正在尝试重定向,但出于某种原因,我使用下面的代码获取了一个apache错误页面

# -> Rewrite START
Options ExecCGI +FollowSymLinks
RewriteEngine On

ErrorDocument 403 http://example.com

### Deny website access to users outsdie our IP addresses
order deny,allow
deny from all
allow from xx.xx.xx.xx
allow from xx.xx.xx.xx
### Deny end

EDITED

有人可以指出我正确的方向。我是.htaccess的新手。我如何在下面的代码中添加另一个IP地址?

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REMOTE_ADDR} !=xx.xx.xx.xx
RewriteRule ^(.*)$ http://example.com [L,R=301]

1 个答案:

答案 0 :(得分:1)

由于循环,您收到错误,因为对403的请求也会导致403(因为IP仍会匹配)。

请尝试使用此代码:

Options ExecCGI +FollowSymLinks

ErrorDocument 403 /

RewriteEngine On

RewriteCond %{REMOTE_ADDR} !^(xx\.yy\.zz\.mm|aa\.bb\.cc\.dd)$
RewriteRule ^.+$ - [F]