I have a directory protected by htaccess. Here is the code I use now:
AuthName \"Test Area\"
Require valid-user
AuthUserFile \"/***/.htpasswd\"
AuthType basi
The accepted answer does not seem to run well with new Apache Versions, since it stopped working as soon as Apache Updates were rolled out on some of my customers servers.
I recommend the following approach:
AuthType Basic
AuthName "NO PUBLIC ACCESS"
AuthUserFile /xxx/.htpasswd
SetEnvIf REQUEST_URI "(path/to/directory/)$" ALLOW
Require env ALLOW
Require valid-user