Web : How to password protect a Web directory with htaccess

By | October 1, 2019

If for any particular reason you need to password protect a Web directory, on an Apache Web server using htaccess, here are steps below :

1. If not already existing, create a file name “.htaccess” at the root of the folder you want to protect :

2. Make sure it is readable by the Web server user (write access can also be granted for convenience, but may represent a security risk) :

3. Add or append the following into the “.htaccess” file (edit AuthUserFile accordingly) :

Note : You need to replace “username” by the actual username you want. You may also append as many users as you need.

4. Create the password file (we recommend putting this file outside of your Document Root (within your home folder but inaccessible by Web visitors for enhanced security) :

5. Create the user/password :

Note : You may repeat the step above for as many users you need and initially entered in the .htaccess file above. If you do not have shell access, there are many generators available on the Web, you may just copy/paste the content to a text file and upload it with

Be Sociable, Share!