简体   繁体   English

拒绝所有访问文件但只有一个ip | htaccess的

[英]Deny all access to a file but one ip | htaccess

I tried the following but DOESNT work(no body can access the file including the IP that i want it to access) 我尝试了以下但DOESNT工作(没有机构可以访问该文件,包括我希望它访问的IP)

<Files something.php>
Order allow,deny
Deny from all
allow from zzz.zzz.zzz.zzz
</Files>

I want to deny the access to a file to all the world except one ip, how do i do this? 我想拒绝除了一个ip之外的所有世界的文件访问,我该怎么做? Thanks 谢谢

I found my answer in an older post, one of the answers in here: .htaccess: how to restrict access to a single file by IP? 我在一篇较旧的帖子中找到了我的答案,其中一个答案在这里: .htaccess:如何通过IP限制对单个文件的访问? , the correct is: ,正确的是:

 <Files something.php>
 Order deny, allow
 Deny from all
 allow from zzz.zzz.zzz.zzz
</Files>

from the original I changed "Order allow, deny" to "Order deny, allow" and it works! 从原来我改变了“订单允许,拒绝”到“命令拒绝,允许”,它的工作原理!

The reason it did not work is because your Deny directive overrode your Allow directive. 它不起作用的原因是因为你的Deny指令覆盖了你的Allow指令。 What Order Allow,Deny does is: 什么Order Allow,Deny做的是:

  1. Evaluate Allow , flag "allow" if any matched. 评估Allow ,如果匹配则标记“允许”。
  2. Evaluate Deny , flag "deny" if any matched (even if previously matched by Allow ) 评估Deny ,标记“拒绝”,如果有任何匹配(即使以前匹配Allow
  3. Evaluate flag. 评估标志。 If flag is not set, deny it. 如果未设置标志,则拒绝它。

So, it is required that you remove Deny from All if you do not want all requests to be Denied. 因此,如果您不希望拒绝所有请求,则需要 Deny from All 删除 Deny from All Just a note for MickeyRoush's answer. 只是MickeyRoush的回答。

As for Order Deny,Allow , it's the "opposite": 至于Order Deny,Allow ,它是“相反的”:

  1. Evaluate Deny , flag "deny" if any matched. 评估Deny ,标记“拒绝”,如果有任何匹配。
  2. Evaluate Allow , flag "allow" if any matched (even if previously matched by Deny ) 评估Allow ,标记“允许”,如果有任何匹配(即使先前与Deny匹配)
  3. Evaluate flag. 评估标志。 If flag is not set, allow it. 如果未设置标志,请允许它。

See the link MickeyRoush gave for more information. 请参阅MickeyRoush提供的链接以获取更多信息。

Actually the first directive you used would work, but it would need to be in the correct place. 实际上你使用的第一个指令会起作用,但它需要在正确的位置。

Order Allow,Deny
<Files something.php>
Allow from zzz.zzz.zzz.zzz
</Files>

Notice that I removed the deny from all as it's not required. 请注意,我删除了所有拒绝,因为它不是必需的。

http://httpd.apache.org/docs/2.2/mod/mod_authz_host.html#order http://httpd.apache.org/docs/2.2/mod/mod_authz_host.html#order

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM