Password Protected Directories
How do I set up password protected directories?
1) Edit httpd.conf
To set up password protected directories you must edit httpd.conf
This file is located in:
C:\FoxServ\Apache\conf
Look for the directory settings for C:\FoxServ\www, these setting will be between
All the settings are between these tags...
Find the following line:
AllowOverride None
and change it to:
AllowOverride AuthConfig
You must also change the following: (notice that the . (period) before htaccess needs to be removed.
AccessFileName htaccess
The following lines prevent htaccess and htpasswd files from being viewed by Web clients. You will need to modify the entries to the following because you're removing the . (period) from the htaccess and htpasswd files:
Order allow,deny
Deny from all
Order allow,deny
Deny from all
2) Create htaccess file
Using a text editor (e.g. Notepad) copy the following code:
AuthType Basic
AuthName "Restricted Files"
AuthUserFile C:\FoxServ\htpasswd
require valid-user
Save the file as "htaccess" (without the quotes) and place it IN the directory you want to be password protected. For example, create a directory called secure and place it in the www directory (the directory can actuallybe called anything you want, we are just using "secure" for this example):
C:\FoxServ\www\secure
NOTE: The third line "AuthUserFile" points to the location of the htpasswd file that we are about to create. You can place the htpasswd file in the same directory as htaccess sice we've denied access to it in httpd.conf, or you can place it above your root directory (www).
3) Create htpasswd file
Open the command prompt (Start -> Accessories -> Command Prompt)
use the cd command to change directories to C:\FoxServ\Apache\bin
cd C:\FoxServ\Apache\bin
The you'll need to run the htpasswd program:
htpasswd -c C:\FoxServ\htpasswd USERNAME
Note the location where you want the htpasswd file to be created. In this example it will be placed in C:\FoxServ This line should be the same as the AuthUserFile line in the htaccess file. (replace USERNAME with the username you want).
A sucessful htpasswd creation looks like this:
C:\FoxServ\Apache\bin>htpasswd -c c:\foxserv\htpasswd USERNAME
Automatically using MD5 format.
New password: ******
Re-type new password: ******
Adding password for user USERNAME
4) Accessing the password protected directory
Using your browser go to:
http://localhost/secure/
You will be prompted for a username and password
Enter the username and password that you created in the htpasswd file.
没有评论:
发表评论