通过 .htaccess 按国家/地区禁止 IP,但允许来自该国家/地区的某些 IP

发布于 2024-12-28 19:36:25 字数 97 浏览 0 评论 0原文

.htaccess 文件,所以请耐心等待。我只是想知道是否有任何方法可以禁止来自特定国家/地区的所有 IP,但只允许被禁止国家/地区的一两个 IP 访问该网站。这可能吗?提前致谢。

.htaccess files so please bear with me. I would just like to know if there is any way I can ban all IP from a specific country but only allow perhaps one or two IPs from the banned country access to the site. Is this possible ? Thanks in advance.

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

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

发布评论

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

评论(1

柠檬心 2025-01-04 19:36:25

http://www.countryipblocks.net/country-blocks/htaccess-deny- format/

要允许某些 ip 使用诸如

Order deny, allow
Allow from 1.2.3.4

EDIT 之类的内容来明确放置它们的位置。

我没有看到 的使用,所以我删除了它。

Order deny, allow
#ips from the blocked countries that are are allowed
Allow from YYY.YYY.YYY.YYY


# 'deny'-code from website 
# only copy the lines starting with 'deny'
deny from XXX.XXX.XX.X/XX 
deny from XXX.XXX.XX.X/XX 
deny from XXX.XXX.XX.X/XX 
# lines starting with a hash are comments so can be removed

# all other ips are allowed

http://www.countryipblocks.net/country-blocks/htaccess-deny-format/

To allow some ips use something like

Order deny, allow
Allow from 1.2.3.4

EDIT to clarify where to put them.

I don't see the use of <limit> so I removed that.

Order deny, allow
#ips from the blocked countries that are are allowed
Allow from YYY.YYY.YYY.YYY


# 'deny'-code from website 
# only copy the lines starting with 'deny'
deny from XXX.XXX.XX.X/XX 
deny from XXX.XXX.XX.X/XX 
deny from XXX.XXX.XX.X/XX 
# lines starting with a hash are comments so can be removed

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