PDA

View Full Version : How to password protect some directory on Apache server using .htaccess and .htpasswd



Fli
03-08-2015, 02:29 PM
We have an website on an hosting server which supports PHP/Apache (most web hostings support these)

How to protect some directory by password?

Create .htaccess file in the directory you want to protect:


AuthType Basic
AuthName "restricted area"
AuthUserFile /home/yourusername/public_html/admin-panel/.htpasswd
require valid-user

Then create .htpasswd file using an online htpasswd generator like http://tools.dynamicdrive.com/password/

example .htpasswd content:

admin:Sdn.Tbi5RlzSR

and make it available at path which you set in .htaccess file (AuthUserFile), you need to enter absolute path to file!