How to Password Protect your Web Pages

14 01 2008

If you want to provide password protection for your webpages, follow the steps below:

Create a .htaccess file under the directory (which you want to protect):

To protect the entire directory

AuthName “Restricted Area”
AuthType Basic
AuthUserFile /docroot/<username>/.htpasswd
AuthGroupFile /dev/null
require valid-user

To protect individual files like test.html, testing.html:

AuthName “Restricted Area”
AuthType Basic
AuthUserFile /docroot/<username>/.htpasswd
AuthGroupFile /dev/null
<Files test.html>
require valid-user
</Files>
<Files testing.html>
require valid-user
</Files>

docroot/username/.htpasswd is the file where you want to put the username(s) and encrypted password(s).

You can create this “htpasswd” file using the command:

#htpasswd -nb username testpass

This command will give you an output like username:P/X0BsSU.aEKM Put this line to your .htpasswd file.


Actions

Information

Leave a comment