How to create basic HTACCESS login to secure your web folder from public access?


HTACCESS login system was used to protect a webfolder from public access. Especially it was used to protect admin section(folder) of any website which got only specific user access. This enables a two layer of authentication which was more secured.



To enable HTACCESS login, you need to place two files into the folder on which you want to enable.

1) .htaccess
2) .htpasswd
.htaccess file holds the lines to prompt the user for a valid login.
.htpasswd file holds the login information for allowed users.
Steps to enable htaccess login in your folder…
Place .htaccess file inside your folder with following lines…

On the above code…

Replace  “MESSAGE TO USER” with a valid prompt message. (i.e. This is private area … Please login to continue …)
Replace “PATH TO HTPASSWD FILE” with the location where your .htpasswd file location (i.e. /home/xxxxx/public_html/administrator/.htpasswd)
Example code…

Now place the .htpasswd file with login information for allowed users.

To create .htpasswd users entry use the following URL…
Generate user entrys from the above URL and place it line by line in the .htpasswd file
Thats all … You are done with simple HTACCESS login setup… Now if you try to access your folder in your browser (i.e. , you will be prompted to login to see the folder content.

Video Tutorial

Share on :