apache 使用 .htaccess 将特定 IP 地址重定向到我主页的特殊页面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2439308/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Redirect a specific IP address to a special page of my homepage with .htaccess
提问by Jim Knopf
How can I use .htaccess to forward a visitor of a specific IP address to a webpage on my server?
如何使用 .htaccess 将特定 IP 地址的访问者转发到我服务器上的网页?
This example causes an infinite loop:
此示例导致无限循环:
RewriteCond %{REMOTE_ADDR} ^123\.3\.123\.123$
RewriteRule ^(.*)$ /specialpage.php [R,L]
I found this on the web but it just does not work:
我在网上找到了这个,但它不起作用:
SetEnvIf REMOTE_ADDR 123.123.123.123 REDIR="redir"
RewriteCond %{REDIR} redir
RewriteRule ^(.*)$ /specialpage.php
Note: My website consists of .htm, html and .php pages.
注意:我的网站由 .htm、html 和 .php 页面组成。
Your help would be very much appreciated.
您的帮助将不胜感激。
采纳答案by Wim
Add a condition to notrewrite when you're already at specialpage:
当您已经在特殊页面时,添加一个不重写的条件:
RewriteCond %{REMOTE_ADDR} ^123\.3\.123\.123$
RewriteCond %{REQUEST_URI} !/specialpage.php
RewriteRule ^(.*)$ /specialpage.php [R,L]
回答by Jim Knopf
Just figured out the solution:
刚刚想出解决方案:
RewriteCond %{REMOTE_ADDR} ^123\.3\.123\.123$
RewriteCond %{REQUEST_URI} !/specialpage.php
RewriteRule .*\.(htm|html|php)$ /specialpage.php [R,L]
Thank you for your help!
感谢您的帮助!

