Creating the .htpasswd file¶
The safe location is anywhere outside of the public accessible folders.
Do not put the .htpasswd created file in the public_html folder.
htpasswd -c /$safe_location/.htpasswd $USERNAME # The shell will request the password to enter and encrypt this in the .htpasswd file.
Using an existing .htaccess file¶
To use this in an existing .htaccess file this simply needs placing in a preferred position in the .htaccess file.
If you wish to use a location to block with basic auth this will then need to be wrapped in a location block.
# Basic Auth Configuration AuthType Basic AuthName "Secure Content" AuthUserFile /$safe_location/.htpasswd require valid-user # End Basic Auth Configuration