2012-03-28 94 views

回答

2

mod_rewrite方式:

RewriteEngine on 
RewriteCond %{REMOTE_ADDR} ^123\.45\.67\.[8-9]$ # your ip here 
RewriteCond %{REQUEST_URI} !^/index/ 
RewriteRule .? /index/ [R,L] 
1

這是你在找什麼?

if($_SERVER['REMOTE_ADDR'] != 'xxx.xxx.xxx.xxx') 
{ 
    header('Location: /index/'); 
} 

您可以指定一個匹配允許的IP的數組。

if(!in_array($_SERVER['REMOTE_ADDR'], array('xxx.xxx.xxx.xxx', 'xxx.xxx.xxx.xxx'))) 
{ 
    header('Location: /index/'); 
}