Basic HTTP Authentication with Apache

Below is an example of how to http authenticate a whole project but leave two subdirectories and all their contents open.

First in the VirtualHost file:

<Directory /var/www/myproject/>
  Options FollowSymLinks
  AllowOverride All
</Directory>

And then this needs to be added to the .htaccess file:

AuthName "Authentication required"
AuthType Basic
AuthUserFile /home/myhome/.htpasswd
Require valid-user
SetEnvIf Request_URI "(/dir1/)$" allow1
SetEnvIf Request_URI "(/dir2/)$" allow2
Order allow,deny
Allow from env=allow1
Allow from env=allow2
Deny from all
Satisfy any

Related Posts

Tags: , ,