Password Protect a Directory with .htaccess

Motivation: protect some directories from being accessed without authorisation.
Solution: using the .httaccess file. You just have to configure one and place it into the directory you want to protect. The code inside the file would look something like this:

1
2
3
4
AuthType Basic
AuthName "guest"
AuthUserFile "/home/user/.htpasswds/public_html/directory2storepass/passwd"
require valid-user
AuthType Basic
AuthName "guest"
AuthUserFile "/home/user/.htpasswds/public_html/directory2storepass/passwd"
require valid-user

Then you have to place the password in the directory you have chosen.
The source I’ve used.

Leave a Reply

Your email address will not be published. Required fields are marked *

*