How to protect a directory under Apache?
This can be done with .htaccess, visitors must input username and password before they can access the protected directory.
Step 1.
Create the file “.htaccess†with the following content under the directory you want to protect, you can specify the password in any place as long as Apache can access it.
AuthUserFile /home/account/passwd/.htpasswd
AuthGroupFile /dev/null
AuthName “Titleâ€
AuthType Basic
Step 2.
Generate the password file “.htpasswd†under the directory /home/account/passwd/ with the following command:
# htpasswd -c .htpasswd user_name
You will be reminded to input password for the user “user_nameâ€, this command can be called multi times to generate multi users.
Step 3.
This step may not be necessary. If there is an entry about the directory you want to protect in Apache configuration file, make sure AllowOverride has the option authconfig.
For example, when protecting Awstats pages, the Apache configuration file should be modified as following:
Options None
AllowOverride authconfig
Order allow,deny
Allow from all
Restart Apache
# /usr/local/sbin/apachectl restart
