Ask for a password, unless from specified IP (Apache)

Print

Q. When accessing a directory in apache, I would like to set up a way to ask for a password from a user if he is not listed on the allowed IP list.

A. This one is a bit of a pain to figure out, so here it is:

<Location />
Order Deny,Allow
Deny from all
AuthType Basic
AuthName "Access Restricted"
AuthUserFile "/var/www/.htpass" #your password file
Require valid-user
Allow from 192.168.5.10
Allow from 192.168.10.10
Allow from 10.10.10.3
Satisfy Any
</Location>

The key here is "Satisfy Any" - only one condition needs to be true.
Web Servers