Host restriction

If you are going to limit directories by host, you need to know a few commands to put in your .htaccess file. First, you can set both the AuthUserFile and the AuthGroupFile to /dev/null, since individual users and groups are not involved in this method of authentication.

	AuthUserFile /dev/null
	AuthGroupFile /dev/null

Next, you name the area you want to limit access to. Users may or may not see this name, depending upon your particular server and their browser.

	AuthName My Secret Stuff

The next line never changes in this type of authentication:

	AuthType Basic

The last part of the file actually deals with the hosts involved.

Specifying the hosts involved

There are two ways that you can specify the hosts that you want to limit:

  1. a full or partial domain-name
  2. a full or partial IP address
You use the commands deny, allow, and order in conjunction with these full or partial names. Here is an example:

	order deny,allow
	deny from all
	allow from 

This would first deny access to all hosts, then make an exception if the IP address were , your current IP address. The order command is only needed when you combine deny and allow. The complete .htaccess file looks like this:

	AuthUserFile /dev/null
	AuthGroupFile /dev/null
	AuthName My Secret Stuff
	AuthType Basic

	order deny,allow
	deny from all
	allow from 

Another example using just the deny command might look like this:

	deny from 128.113.

This would deny access to any machine whose IP address started with 128.113. (i.e. a machine at Rensselaer Polytechnic Institute). All other machines would be allowed by default. The complete .htaccess file using this example looks like this:

	AuthUserFile /dev/null
	AuthGroupFile /dev/null
	AuthName My Secret Stuff
	AuthType Basic

	deny from 128.113.

All that remains is to put the .htaccess file in the directory that you want to protect. The server does the rest!

You may now proceed to the tutorial on password-based restriction or the tutorial on how to combine both methods. In addition, there is a page of resources for some advanced uses of user authentication.

Justin R. Miller / justin@openup.com / 04.24.98