【发布时间】:2016-02-20 17:44:57
【问题描述】:
我一直在问与 mod_rewrite 相关的问题,所以首先很抱歉向大家发送相同主题的垃圾邮件。我现在面临的问题是我想根据用户 IP 地址重定向我的网页。因此,当您访问“localhost/index”时,如果 IP 地址以 10 开头,它应该将您重定向到 example.html,但如果不是,我想将用户重定向到 readme.html 页面。 readme.html、index.html 和 example.html 位于同一目录 (htdocs) 中。
这是目前为止的代码;
DocumentRoot "usr/local/apache2/htdocs"
<Directory "/htdocs">
Options FollowSymLinks
AllowOverride None
Order allow,deny
allow from all
RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_ADDR} ^10
RewriteRule ^index.html$ readme.html [R,NC]
</Directory>
试过这样做;
//RewriteCond %{REMOTE_ADDR} ^!10
//RewriteRule ^ index.html$ example.html [R,NC]
但这不起作用
所以现在我只允许 IP 地址以 10 开头的用户访问该站点。
我查看了文档,但找不到解决方法,这就是这篇文章的原因,请有人帮忙
谢谢
【问题讨论】:
-
如果想看之前的帖子,stackoverflow.com/questions/33787392/…
标签: apache mod-rewrite directory server-side httpd.conf