|Do you know where your variables are?|
Re: cgi and https (mildly off topic)by Spenser (Friar)
|on Nov 27, 2001 at 10:56 UTC||Need Help??|
As Dogma has alluded to, .htaccess can be problematic when dealing with many users and a lot of usage. Besides what has already been pointed out here, .htaccess also has a problem with repeated verification. Once a user enters a directory containing a .htaccess file, the browser is called upon to provide user name and password for each page requested. The user is only asked once, but the browser, behind the scenes, is having to authenticate with each page requested. This slows things down a bit and could be a real drain on the system with a large number of users.
A good alternative to .htaccess is to modify the Apache configuration file. In RedHat Linux 7.0 it's /etc/httpd/conf/httpd.conf. Check the man pages for httpd on your system, if different. The advantage is that when you enter the protected directory, authentication is conducted only once and not repeated with each page retrieved. This option may not be available, though, if you're renting space on someone else's server.
Assuming you do have access to httpd.conf, here's a sample of text you would include in the configuration file:
A directive like this needs to be put in the correct, general location in the httpd.conf file. Just search for <Directory for the example and place it in that area.
You'll notice that I specify the directory protected in the openning tag (with no trailing slash). I also specify where to find the user file (staff) which contains the user names and their encrypted passwords.
Read the man pages on htpasswd, obviously. But, basically, you create the user file in the directory you want and your first user by typing the following command at the command prompt:
htpasswd -c staff bob
One last comment about my sample configuration: I'm protecting an intranet section of my web site for employees to use from home or work. If they're outside the office, I want them to be authenticated so I can be sure of who it is that's coming in. However, if they're inside my local network, I don't want them to have to worry about authenticating. So I've added the line "Allow from 10.1.71.0/24" where my network subnet is 10.1.71.x.