PASSWORD PROTECTING A FOLDER ON A WEB SITE

In order to create password protection on an Apache Web Server, it is necessary to have 2 special files stored within the folder to be protected. These files are called .htaccess and .htpasswd. (Note that they do not have a suffix) Both files can be created in Notepad (or any other text editor) and then FTP'd into the appropriate folder on the Web Server.

The .htaccess File

The content of .htaccess should be as follows:-

AuthUserFile /xyz/.htpasswd
AuthName "Enter User Name and Password"
AuthType Basic

<Limit GET>
require valid-user
</Limit>

The colours used above are for illustration only. xyz should be replaced by the full path to the folder. Note that there is no space between the final / and .htpasswd.

The text between the "" in line 2 is what will appear in the log in window. All other text MUST be exactly as shown above including spaces where appropriate and observing letter case

Example:- If you wish to protect the folder /html/customerweb/secrets, the first line would be:-

AuthUserFile /home/customerweb/html/secrets/.htpasswd

If you wish to say 'Hello, please log on' at the log on window, the second line would be:-

AuthName "Hello, please log on"

When you save the file in the text editor, it may automatically insert .txt (or similar) after .htaccess. You must rename the file so that there is no suffix before FTP'ing it to the Web Server.

The .htpasswd File

Go to http://www.inch.com/info/tech/HOWTOS/htaccess/htpasswd.html and enter your chosen User Name and Password. An encrypted version of the password will be created.

Cut and Paste this into a blank page in Notepad (or other text editor) then save the file as .htpasswd. Once again, you must ensure that no suffix is attached before FTP'ing the file to the Web Server.

If you wish to create other User Names and Passwords which will provide access to the same folder, go back to http://www.inch.com/info/tech/HOWTOS/htaccess/htpasswd.html and create a new pair then open the existing .htpasswd file in a text editor and cut and paste the new pair on a new line. Check that no suffix has been added to the file name and FTP the modified file to the Web Server. Both pairs of User Name and Password will now work.