Instruction
1
The easiest way to close the access to the site the password is to use the built-in web server that hosts the website. Configuring the Apache server such that if any server folder is a file with the name ".htaccess", then when you request any document from that folder (e.g., web pages), Apache will follow the rules contained in the file .htaccess. In this file you can put Directive restrict access to all or only some of the documents in the folder. The mechanism we use.Step 1: Create a file .htaccessСоздать an empty file with the name .the easiest htaccess in a plain text editor - Notepad. When you save the file, Notepad automatically added the. txt extension in the drop-down list "file type" of the save dialog it is necessary to select "All files".The Directive, which need to be written in .htaccess can look like this:AuthType Basic
AuthName "restricted area!"
AuthUserFile /usr/host/mysite/.htpasswd
require valid-megilla string (AuthType Basic) tells the server that the authentication of visitors is required.The second (AuthName "restricted area!") specifies the text you want to display on the form of entering a username and password.The third (AuthUserFile /usr/host/mysite/.htpasswd) shows the path of the file in which to store permitted usernames and passwords. Here is necessary to indicate the "absolute path", that is, from the root of the server and specify an entire directory tree. This is the full path that we can see in the address bar of Windows Explorer when open any folder. On servers that host websites it usually has the form /pub/home/imaagine/..../filename. The path from the root servers to your site can be found in the administration panel of the website or ask tech support of your hosting. You can find out on their own, but this will require the use of any programming language - for example, in PHP it can be obtained from the results of the command phpinfo().The fourth line require valid-user) means that nothing but entering the correct username and password to access the documents in this directory is not required. In fact, to break visitors into groups and give different groups different access rights to different folders.
2
Step 2: create a file .htpasswdТеперь you must create a password file, the path to which we have specified in. htaccess. By default it is given a name."htpasswd", although this is not necessary - you can specify a different name. This file contains login and password, and the password it contains in an encrypted feed. To encrypt the password, you will have to use a special program - htpasswd.exe. If you have not installed Apache server, then take it for example here - http://www.intrex.net/techsupp/htpasswd.exe . Need to run it from the command line. In Windows XP, I do it this way: put htpasswd.exe in a separate folder, click the folder, right-click and from the menu select "Run command prompt here". At the command prompt we need to type:htpasswd -cm .htpasswd adminЗдесь:
htpasswd is the name of the startup program;
-cm - modifier which indicates that it is necessary to create a new password file;
.htpasswd is the name for the new file;
admin - login of the first user that must be added to the file.After pressing Enter you will be prompted to enter and repeat a password for this user. When the password is entered and verified, in a folder create the file we need .htpasswd with one pair of login and password.To add more users to put back htpasswd.exe but instead of modifier -cm to specify only -m.At the command prompt you can see and help htpasswd.exe - for this you need набрать:htpasswd.exe /?
The command line
3
Step 3: download files to the server.You only have to place both file (.htaccess and .htpasswd) on the server. This can be done by any ftp client or through file Manager in admin panel of your site. File .htaccess placed in the same folder where you store pages that you need to protect with a password. Will be protected not only files in that folder, but all sub-folders. And the file .htpasswd is placed in the folder, the path to which was specified in. htaccess. Typically, the password file is stored in the folder one level above the root directory of the site - from the Internet to him was not direct access.