【发布时间】:2012-04-12 06:26:22
【问题描述】:
如果用户没有我的 IP 地址,我想将他们重定向到网站的 /index/ 区域。
我该怎么做?
谢谢。
【问题讨论】:
-
你列出了 php 和 .htaccess - 它们是广泛的主题,交付方法大相径庭
标签: php apache .htaccess http-headers directoryindex
如果用户没有我的 IP 地址,我想将他们重定向到网站的 /index/ 区域。
我该怎么做?
谢谢。
【问题讨论】:
标签: php apache .htaccess http-headers directoryindex
这就是你要找的吗?
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/');
}
【讨论】:
mod_rewrite 方式:
RewriteEngine on
RewriteCond %{REMOTE_ADDR} ^123\.45\.67\.[8-9]$ # your ip here
RewriteCond %{REQUEST_URI} !^/index/
RewriteRule .? /index/ [R,L]
【讨论】: