Wednesday, July 1, 2009

password protecting directories using .htaccess

If you want to protect /home/username/publlic_html do as follows

cd /home/username/publlic_html
touch .htaccess [if it is already there you can use it no need to create]

Add the following line to the .htaccess file

AuthUserFile /home/username/public_html/.htpasswd
AuthName "Title for Protected Site"
AuthType Basic
Require valid-user

The next stage is creating the .htpasswd file create it in the same directory as .htaccess

cd /home/username/public_html [same place where your .htaccess is]

touch .htpasswd
htpasswd -c .htpasswd test
New password:
Re-type new password:
Adding password for user test

Thats it dont forget to change ownership and permission

No comments:

Post a Comment