Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)

<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? Thanks

like image 687
MariaZ Avatar asked Dec 10 '25 01:12

MariaZ


2 Answers

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?, 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!

like image 107
MariaZ Avatar answered Dec 13 '25 07:12

MariaZ


The reason it did not work is because your Deny directive overrode your Allow directive. What Order Allow,Deny does is:

  1. Evaluate Allow, flag "allow" if any matched.
  2. Evaluate Deny, flag "deny" if any matched (even if previously matched by 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. Just a note for MickeyRoush's answer.

As for Order Deny,Allow, it's the "opposite":

  1. Evaluate Deny, flag "deny" if any matched.
  2. Evaluate Allow, flag "allow" if any matched (even if previously matched by Deny)
  3. Evaluate flag. If flag is not set, allow it.

See the link MickeyRoush gave for more information.

like image 36
jerielmari Avatar answered Dec 13 '25 07:12

jerielmari