Restricting access to directories and html files using HtAccess

Introduction

HTAccess is a NCSA-compatible (our server is) way to use password protection on HTML documents and server directories. You can set up your web directories to require userids and passwords for access to web objects in them. When properly set up, the web server will request a userid and password from the web browser. The web browser in turn requests this information in a pop-up window; after you provide the information, the browser remembers the userid & password for the duration of the session and supplies them to the web server each time you access protected objects.

This means that you need to exit your browsers when you have finished using them. Otherwise, hackers can continue to use your browser to access protected files without having to enter a userid and password.

In this context each person accessing the protected content does not need to have an individual userid. For example, all students in a class may share a single userid.

Notes about HtAccess files:

  1. They must be world readable, or the webserver will not be able to see what needs restrictions and will restrict your entire directory. The directory in which the files are kept should be world searchable.
  2. They restrict in the directory they are located in, and all subdirectories, this means if you have a broken .htaccess file and you move it from your public_html directory to your home directory, your webpage will still be unviewable.
  3. If there is an error in your .htaccess then access to your webpage will be restricted until the error is corrected.

Basic Procedure

There are three files involved: .htaccess, .htgroup and .htpasswd. The basic procedure is as follows:

Deleting users

To delete one or more users, delete the corresponding line(s) in the .htpasswd file. To delete all users, delete the whole .htpasswd file, and remove mention of it from the .htaccess file (unless you plan to create some new users).

Security Issues

It is possible to use names other than .htpasswd and .htgroup for the password and group files. This is not advisable, though, since this may create an opportunity for the contents of these files to be revealed to web users. The web server will not allow web access to any files beginning with .ht, or to any files located outside of public_html (unless they can be accessed by symbolic links contained within public_html). You should keep this in mind if you choose different names for these files. However, the best way to avoid this problem is to use the standard names, as above.

General References on HtAccess

These are public documents that have more information about password protecting a site with HtAccess


Last updated 16 September 2006