Setting up a password protected directory

Using an .htaccess file to password protect a folder

There are two steps to protecting a folder with a .htaccess file.

Step 1:

Using Notepad (or another text editor), create a file called .htaccess (please note the period). Enter the following text in the file:

AuthUserFile /home/[YOURUSER]/htpasswd/[FOLDER]
AuthName "Please enter your username and password"
AuthType Basic

require valid-user

Replace [YOURUSER] with your Zenutech username. To find your username, login to the Zenutech Control Panel, click ‘Account Information’->’Account Summary’. You will find your username in the second column.

Replace [FOLDER] with the name of the folder you are protecting. For example, if you want to protect www.demo123.com/members, then [FOLDER] should be changed to ‘members’. If you want to protect a subfolder, such as www.demo123.com/members/subfolder7 , then [FOLDER] should be named ‘subfolder7′.

Save this .htaccess file; it must be called ‘.htaccess’ with no file extension after the name. Then upload the file into the folder you want to protect. Now when you visit that folder, you will be asked for a username. There still isn’t one setup, though, so keep reading!

Step 2:

Begin by creating a file with the same name as the [FOLDER] from above that you want protected. This file will hold the usernames and passwords that have access to the folder.

Now, because it wouldn’t be very secure to store the passwords in plain text here, we need to encrypt them. This is done with a tool called ‘htpasswd’, which is available for free on a number of webpages, such as this one. Run each username and password through the tool, and then enter the username with the encrypted password into the file. For example, with username ‘mary’ and password ‘blackpin123′, enter this into the file:

mary:n/KK81Nclh0zQ

Each user should be on a seperate line. On the server, you will need to create a folder in the root of your FTP structure(i.e. /home/[YOURUSER]/) named ‘htpasswd’. Now you can upload the new file to this folder.

All that remains is for you to try it out!

Posted 2008-06-16 in Site Management    Popularity: 10%