我已经看遍了,但不断遇到关于目录级别 IP 限制的相同信息,通常看起来像这样:
Order Deny,Allow
Deny from all
Allow from 123.123.123.123
是否可以将相同类型的访问限制绑定到页面/文档?
这将允许来自 IP 127.0.0.1 的人或作为有效用户登录。将其粘贴在您的配置或 .htaccess 文件中。
<Files learn.php>
Satisfy any
Order deny,allow
Deny from all
Allow from 127.0.0.1
AuthType Basic
AuthName "private"
AuthUserFile /var/www/phpexperts.pro/.htpasswd
AuthGroupFile /dev/null
Require valid-user
</Files>
仅IP:
<Files learn.php>
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Files>
这绝对回答了你的问题。
我认为该指令需要是:
Order deny,allow
为了使上述答案起作用(至少对于 IP Alone 解决方案)。
基于 Mod 重写的解决方案:
RewriteEngine on
RewriteCond %{REMOTE_ADDR} !^Y\.O\.U\.R\.IP$
RewriteRule ^file\.php$ - [F,L]
如果客户端 ip 与 RewriteCond 模式中的 ip 地址不匹配,上面的 rewriteRule 将拒绝所有对file.php的请求
有关更新的 Apache 2.4 示例:
<Files file.html>
Require ip 123.123.123.123
</Files>
以下是有关其他选项和示例的更深入的文档:https<Files>
://httpd.apache.org/docs/2.4/howto/access.html 和指令的文档: https ://httpd.apache.org/docs /2.4/mod/core.html#files
请注意,
<Files>
可以嵌套在<Directory>
部分内以限制它们适用的文件系统部分。