使用 .htaccess 将特定 IP 地址重定向到我主页的特殊页面

发布于 2024-08-25 00:17:59 字数 411 浏览 3 评论 0原文

如何使用 .htaccess 将特定 IP 地址的访问者转发到我的服务器上的网页?

这个例子会导致无限循环:

RewriteCond %{REMOTE_ADDR} ^123\.\123\.123\.123$
RewriteRule ^(.*)$ /specialpage.php [R,L] 

我在网上找到了这个,但它不起作用:

SetEnvIf REMOTE_ADDR 123.123.123.123 REDIR="redir"
RewriteCond %{REDIR} redir
RewriteRule ^(.*)$ /specialpage.php

注意:我的网站由 .htm、html 和 .php 页面组成。

非常感谢您的帮助。

How can I use .htaccess to forward a visitor of a specific IP address to a webpage on my server?

This example causes an infinite loop:

RewriteCond %{REMOTE_ADDR} ^123\.\123\.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.

Your help would be very much appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

紫罗兰の梦幻 2024-09-01 00:17:59

添加一个条件,以便在您已经处于特殊页面时重写:

RewriteCond %{REMOTE_ADDR} ^123\.\123\.123\.123$
RewriteCond %{REQUEST_URI} !/specialpage.php
RewriteRule ^(.*)$ /specialpage.php [R,L] 

Add a condition to not rewrite when you're already at specialpage:

RewriteCond %{REMOTE_ADDR} ^123\.\123\.123\.123$
RewriteCond %{REQUEST_URI} !/specialpage.php
RewriteRule ^(.*)$ /specialpage.php [R,L] 
送舟行 2024-09-01 00:17:59

刚刚找到解决方案:

RewriteCond %{REMOTE_ADDR} ^123\.\123\.123\.123$
RewriteCond %{REQUEST_URI} !/specialpage.php
RewriteRule .*\.(htm|html|php)$ /specialpage.php [R,L]

谢谢您的帮助!

Just figured out the solution:

RewriteCond %{REMOTE_ADDR} ^123\.\123\.123\.123$
RewriteCond %{REQUEST_URI} !/specialpage.php
RewriteRule .*\.(htm|html|php)$ /specialpage.php [R,L]

Thank you for your help!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文