htaccess 的 IP 限制

发布于 2024-07-14 10:25:21 字数 796 浏览 7 评论 0原文

我想限制整个站点,只有两个 IP 可以进入该站点。 我的 .htaccess 中有以下内容(位于网站的根目录):(

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)

如您所见,我只允许 322.322.322.322 和 311.311 中的所有 IP .311.0/24,并拒绝其他人。 我想要的是,当任何人从另一个IP进入该网站时,他会看到error403.html页面。

过滤器工作正常,但重定向不行。 当我尝试从拒绝 IP 进入该站点时,我看到一条 Apache 消息:

Found
The document has moved here

其中“此处”是指向 error403.html 的链接。

我想我甚至限制了 error403.html 页面。

我怎样才能做到这一限制,但允许查看错误页面? 我是否应该将 error403.html 页面移动到另一个目录(即 /views/error/ )并将其他 .htaccess 放入其中,从而允许该文件中的所有 IP?

先感谢您!

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

(Obviously, these are fake IPs, in my .htaccess they are the right IPs)

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.

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

Where "here" is a link to error403.html.

I think I'm restricting even the error403.html page.

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?

Thank you in advance!

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

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

发布评论

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

评论(1

酸甜透明夹心 2024-07-21 10:25:21

是的,你已经回答了你自己的问题。 :) 将所有未受保护的页面移至另一个目录,该目录的 .htaccess 包含正确的AllowDeny

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.

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