How to protect directory access with authentication
Introduction
You carry out this operation thanks to the .htaccess file. Before proceeding, it is necessary to specify some things about the .htaccess files. First of all, realize that these files are specific for web servers, and that these files do not appear in the branched directory concerned if the service provider has access to a directory (that does not contain the index page, and so the listing is allowed). Next, you must take into account the indicated parameters for a .htaccess file that applies to the directory or the file installed, and all its sub-directories.
Procedures to follow
Create the password file
Note : In Windows, you cannot directly create the .htaccess or .htpasswd files. But you can rename these files, transfer them to your web space, and then rename them back to .htaccess or .htpasswd on the FTP client.
Next, create the file that contains the list of users and passwords for those who will have authentic access. In general, you can create
.htpasswd which will be used by
.htaccess. It is actually a simple text file that indicates the user names and their passwords in an encrpyted format. On our site you can find a page for encrypting a password:
http://www.ovh.co.uk/cgi-bin/crypt.pl
After filling in the first two fields and clicking on "encryption", you can recover the encrypted password in the "password" field. Next just copy the text corresponding to the
.htpasswd file (see below).
The
.htpasswd file does not necessarily have to be saved in the same place as
.htaccess. You can, for example, place it at the root of your web site, and use it for protecting different directories of your site. Alone, the
.htpasswd file can be used by several
.htaccess files. The
.htpasswd file must contain a line for the user to enter their user name and password.
These following lines take on this form:
user:encrypted_password
Once the .htpasswd file is created, all that is left is to place it on your website with the following step: the creation of the .htaccess files.
Create the .htaccess files
To completely block access to a directory, create the .htaccess text file like below, and place it in a protected directory:
AuthUserFile /home/your_login_ftp/www/'access path tp file .htpasswd'/.htpasswd
AuthGroupFile /dev/null
AuthName "Restraint Access"
AuthType Basic
<Limit GET POST>
require valid-user
</Limit>