.htaccess:如何通过IP限制对单个文件的访问?
我已经查看了所有内容,但不断遇到有关目录级 IP 限制的相同信息,通常看起来像这样:
Order Deny,Allow
Deny from all
Allow from 123.123.123.123
是否可以将相同类型的访问限制绑定到页面/文档?
I've look all over, but keeps running into same info that talks about directory level IP restriction, which usually looks something like this:
Order Deny,Allow
Deny from all
Allow from 123.123.123.123
Is it possible to have same type of access restriction tied to a page/document?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这将允许来自 IP 127.0.0.1 的人或作为有效用户登录。将其粘贴在您的配置或 .htaccess 文件中。
仅 IP:
这绝对回答了您的问题。
This will allow either someone from IP 127.0.0.1 or logged as a valid user. Stick it either in your config or .htaccess file.
IP Alone:
That definitely answers your question.
我认为该指令需要是:
为了使上述答案起作用(至少对于单独的 IP 解决方案而言)。
I think the directive needs to be:
for the answer above to work (at least for the IP Alone solution).
基于 Mod-rewrite 的解决方案:
如果客户端 ip 与 RewriteCond 模式中的 ip 地址不匹配,上面的 rewriteRule 将拒绝所有对 file.php 的请求
Mod-rewrite based solution :
The rewriteRule above will deny all requests to file.php if client ip does not match the ip address in the RewriteCond's pattern
有关更新的 Apache 2.4 示例:
以下是有关其他选项和示例的更深入的文档:https://httpd.apache.org/docs/2.4/howto/access.html 以及
指令的文档:https://httpd.apache.org/docs/2.4/mod/core.html#文件For a more up to date Apache 2.4 example:
Here are the more in depth docs for additional options and examples: https://httpd.apache.org/docs/2.4/howto/access.html and the docs for the
<Files>
directive: https://httpd.apache.org/docs/2.4/mod/core.html#files