Basic Authentication for All Except Listed User Agents in Apache

Solution 1:

After searching for quite a bit and experimenting, I came up with the answer. One needs these lines in their .htaccess file:

SetEnvIf User-Agent ^VipAgent1 vip_agent
SetEnvIf User-Agent ^VipAgent2 vip_agent

Order Allow,Deny
Allow from env=vip_agent

AuthType Basic
AuthName "Protected Login"
AuthUserFile /path/to/htpasswd
Require valid-user

Satisfy any

In addition, for this to work, one would need to make sure that mod_rewrite, mod_authn_file, and mod_setenvif are enabled in httpd.conf and also this directive is set there:

AllowOverride All

This configuration gives access for requests with User Agent starting "VipAgent1" and "VipAgent2", but asks for the authentication credentials for all other visitors.