使用 htaccess 限制 IP [英] IP restriction with htaccess
问题描述
我想以只有两个 IP 可以进入该站点的方式限制整个站点.我的 .htaccess(在站点的根目录)中有以下内容:
I want to restrict an entire site in such a way that just two IPs could enter the site. I have the following in my .htaccess (at the root of site):
ErrorDocument 403 http://www.example.com/views/error403.html
Order Deny,Allow
Deny from all
Allow from 311.311.311 322.322.322.322
ErrorDocument 404 /views/error404.html
ErrorDocument 500 views/error500.html
(显然,这些是假 IP,在我的 .htaccess 中它们是正确的 IP)
(Obviously, these are fake IPs, in my .htaccess they are the right IPs)
如您所见,我只允许 322.322.322.322 和来自 311.311.311.0/24 的所有 IP,并拒绝其他人.我想要的是,当任何人从另一个 IP 进入该站点时,他会看到 error403.html 页面.
As you can see, I allow just 322.322.322.322 and all IPs from 311.311.311.0/24, and deny for the rest of people. What I want is that when anybody enter the site from another IP, he'll view the error403.html page.
过滤器工作正常,但重定向无效.当我尝试从拒绝 IP 进入站点时,我看到一条 Apache 消息:
The filter is working fine, but not the redirection. When I try to enter the site from a deny IP, I see an Apache message:
Found
The document has moved here
此处"是指向 error403.html 的链接.
Where "here" is a link to error403.html.
我想我甚至限制了 error403.html 页面.
I think I'm restricting even the error403.html page.
如何做这个限制,但允许查看错误页面?我是否应该将 error403.html 页面移动到另一个目录(即/views/error/)并将其他 .htaccess 放入其中,允许该文件中的所有 IP?
How can I do this restriction, but allowing the view of the error page? Should I move error403.html page to another directory (i.e., /views/error/ ) and put other .htaccess in it, allowing in that file all the IPs?
先谢谢你!
推荐答案
是的,您已经回答了自己的问题.:) 将所有不受保护的页面移动到另一个目录中,该目录具有自己的 .htaccess
,其中包含正确的 Allow
和 Deny
.
Yes, you have answered your own question. :) Move all non-protected pages into another directory with its own .htaccess
containing the proper Allow
and Deny
.
这篇关于使用 htaccess 限制 IP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!