≡ Menu

How To Password Protect Website or Directory with htaccess

If you are working on a website and want only selected people to access it,then the best option is to password protect the site or the root directory.This could be done easily by placing two files in the directory, .htaccess and .htpasswd.

image

.htaccess file

AuthType Basic
AuthName "restricted area"
AuthUserFile /path/to/the/directory/you/are/protecting/.htpasswd
require valid-user

Place the code in a text file and name it “.htaccess” and place it in the directory you want to password protect.Also note that the AuthUserFile should have the absolute path to the directory.It will be like /home/user/public_html/website/subdirectory/.htpasswd

You should be able to to echo out a phpinfo(); on a page in that directory to scope this directory out.

.htpasswd file

username:password

“.htpasswd” file should have one username and password per line separated by a colon.Place this file in the same directory as “.htaccess” file.After placing both the files your directory or website will be password protected.

Comments on this entry are closed.

  • Anonymous April 18, 2009, 12:26 pm

    how to hack password protecting sites