Is there any way to tell Apache2 to prompt for username and password
when it sees a .htaccess file in a directory?
At the moment, I need to define the directory in the following
fashion in Apache2 conf file but it becomes a problem as I have thousands of directories that needs .htaccess files.
For example, assuming /website is DirectoryRoot then protect /website/a1, /website/b2 etc. I am aware of the fact that protecting one directory would protect all directories below it.
<Directory "/website/dir">
AllowOverride All
Options Indexes
Order allow,deny
Allow from all
AuthUserFile /website/dir/.htaccess
</Directory>
I just noticed from this line that you misunderstand the AuthUserFile directive:
AuthUserFile /website/dir/.htaccess
The AuthUserFile contains the usernames and passwords. However a .htaccess file is not meant to hold that, and you seem to understand that. Rather a .htaccess file contains Apache directives, similar to those in httpd.conf but only a subset of the directives is allowed.
In fact the AuthUserFile should not be located within the web content directories, otherwise it could be fetched by web client and then all your passwords are known.
If you had wanted to change the “htaccess” file from the default of .htaccess, the directive you want is AccessFileName. Since you are already using .htaccess, you don’t need such a directive.
So remove the AuthUserFile directive and look for the reason it’s not paying attention to your LDAP directives. Do you have the ldap auth module loaded and are the directives correct? Check those things.