.htaccess – password protection

The main advantage of using .htaccess is to protect access to directories. When you have a situation to keep files private, or to be accessed only by a set of members, we can apply htacces at those times. We can make each files in a directory as password protected.

For instance, in order to try it locally, try the following code. We need to create a username and password file first. It looks like


We can have any number of users in the list.

In the .htaccess file include the following lines

AuthName “Admin Area”
AuthUserFile /xampp/htdocs/sample/.htpwd
AuthType Basic
require valid-user

Here we have to specify the path of the password file. It can be located anywhere in the server.The first line denotes the message to be displayed as the title of the pop-up box.

The popup box appers as follows in firefox


Follow me


Web Developer at Energy Alternatives India
I'm interested in developing Web applications andkeen on learning new technologies.

View Nagarajan's Profile
Follow me

Latest posts by Nagarajan (see all)

Leave a Reply

Your email address will not be published. Required fields are marked *