MariaZ
MariaZ

Reputation: 1747

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

Upvotes: 3

Views: 5101

Answers (3)

jerielmari
jerielmari

Reputation: 171

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.

Upvotes: 1

MickeyRoush
MickeyRoush

Reputation: 1264

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

Upvotes: 0

MariaZ
MariaZ

Reputation: 1747

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!

Upvotes: 1

Related Questions