To find out how to controll the Apache2 .htaccess authentication forced me hours to search a solution which a ton of solutions that didn't work or was complicated as hell.
All you need:
SetEnvIf Request_URI "^/mydir/?" allow
AuthUserFile /your/.htpasswd
AuthGroupFile /dev/null
AuthName "Restricted"
AuthType Basic
Require valid-user
Require env allow
To find out how to controll the Apache2 .htaccess authentication forced me hours to search a solution which a ton of solutions that didn't work or was complicated as hell.
See Comment of MrWhite, your can try:
SetEnvIf Request_URI "^/mydir/?" allow
AuthUserFile /your/.htpasswd
AuthGroupFile /dev/null
AuthName "Restricted"
AuthType Basic
Require valid-user
Require env allow