【问题标题】:mod_rewrite - How to rewrite to a page based on ip addressmod_rewrite - 如何根据 IP 地址重写页面
【发布时间】: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 开头的用户访问该站点。

我查看了文档,但找不到解决方法,这就是这篇文章的原因,请有人帮忙

谢谢

【问题讨论】:

标签: apache mod-rewrite directory server-side httpd.conf


【解决方案1】:

试试这个。

RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_ADDR} ^10 
RewriteRule ^index.html$ example.html [R,NC]
RewriteRule ^index.html$ readme.html [R,NC]

阅读更多关于rewriteRule R flag

【讨论】:

    猜你喜欢
    • 2011-01-27
    • 2012-04-07
    • 2020-03-28
    • 2013-02-27
    • 2018-04-05
    • 1970-01-01
    相关资源
    最近更新 更多