Limiting Access
This information only pertains to Hurricane Electric's Shared Web Hosting package. There may be different information in our other categories.
This document demonstrates the use .htaccess to restrict access to web documents by user and password.
The Restricted Access Document
The document "Restricted Information" is only available to user john with password orange and user sheri with password apple. The first time you click on "Restricted Information", your web browser should prompt you for a user name and password. If it does not you may be using a web browser which is not HTTP authentication capable.
Ingredients
NOTE: Please make sure you are setting this up in the directory that you want passwd protected. The .htpasswd file will end up in the wrong directory otherwise. For more infomation on how to use Unix, please check out our Unix Tutorial.
- The web document to be protected - Actually, access is restricted by directory so all files in the same directory will be protected.
- The file .htaccess - This file should be in the directory which contains the documents to restrict access to. The contents of this file specify the name of the password file. For example if you were user jdoe with web documents in the local directory "/home/jdoe/public_html/goodstuff" that you wanted to restrict access to, your .htaccess might look like:
AuthUserFile /home/jdoe/public_html/goodstuff/.htpasswd AuthName jdoe_goodstuff AuthType Basic Require valid-user
- Note that .htaccess will not work if there are extra spaces after AuthUserFile.
- The file .htpasswd - This file contains the passwords of the users. To create the .htpasswd file log in to this server using SSH, change directory to the directory you want to restrict access to, and type:
htpasswd -c .htpasswd someuser
for the first user (where someuser is the username). You will then be prompted twice for the user's password. The -c option causes the .htpasswd file to be created. For each additional user type:
htpasswd .htpasswd someuser
NOTE: There is no correspondence between the usernames and passwords used for accounts on this server and usernames and passwords in any specific .htpasswd file. A user doesn't need to have an account on this system in order to be validated for access to files protected by HTTP-based authentication.
Further Study
This example limits access by user and password, however you can also restrict access by domain. To find out more read the Mosaic User Authentication Tutorial.
Other
This lists some of the other varibles you can put into your .htaccess file.
For more information, please find the Apache documentation here: