Here is a sample .htaccess file. This sample file would restrict the directory in which it was placed. Users wishing to access that directory would have to have a username/password combination listed in the file
passwords.txt
located in user johndoe
's home directory.
AuthUserFile /users/j/johndoe/passwords.txt AuthName John Doe's Members-Only Area AuthType Basic <Limit GET POST PUT> require valid-user </Limit> |
Next...
After creating this file and storing it in the directory you wish to protect, you should create the password file you reference in your AuthUserFile directive using the "htpasswd" utility. htpasswd allows you to create a password file with encrypted passwords. It's usage is as follows:htpasswd [-c] passwordfile username
where passwordfile is the name of the password file, and username is the username you want to create or modify. The -c option would be used to tell htpasswd that the password file does not exist yet and should be created. Obviously, you only need to use it the very first time, because after that, the password file will exist.
Following our example, user johndoe would go to his home directory and create the password file there. In order to correspond to the .htaccess file, it should be named "passwords.txt". He would type as follows: (Note that what he would actually type is in boldface type. Everything else is output returned by the system. Also note that passwords do not appear on the screen when typed, which is why nothing appears next to the password prompts below.)
netmar> cd ~ netmar> htpasswd -c passwords.txt jane Adding password for jane. New password: Re-type new password: netmar> htpasswd passwords.txt joe Adding password for joe. New password: Re-type new password: netmar> htpasswd passwords.txt jim Adding password for jim. New password: Re-type new password:
Things to watch for
It is strongly recommended that you login via telnet or SiteMaster to create your .htaccess file. After logging in, simply cd to the directory in your www directory that you wish to protect and type "edit .htaccess" at the prompt.If you must create the file on your local computer and upload it, make sure you upload it with your FTP client in ASCII mode.