The file for setting access to the .htaccess server.

Site building

File for setting access to the server. Htaccess

Author: Maxim Prikhodko
Published on November 30, 2005

Since among the server systems the most popular operating system is Unix, then the most common server is not MS IIS , but Apache (the version of which, however, exists for Windows ).

When the name of your site is entered in the browser line, it is the server that decides which files to show and how. And you can control the operation of the server with respect to the website by manipulating the configuration file. Htaccess , any change of which immediately takes effect.

Syntax. Htaccess has a rigid structure, non-observance of which leads to server errors, therefore it is necessary to fulfill the following two requirements:

  1. The paths to the files (directories) are specified from the root of the server. For example: / opt / home / www.mysite.ru / htdocs / config /. Htpasswords

  2. Domains are indicated with a protocol. For example: Redirect / http://www.site.ru

The file should be called "point" htaccess and be written in UNIX-format. In FAR, for example, when editing, you can press Shift + F2 and select the menu item "Save as UNIX-text".

Here are simple examples of managing access to a site using a file. Htaccess :

Prevent all files:

Deny from all

Here all means "all".

Allow access from a specific IP address (for example, 192.13.237.14):

Order allow deny
Deny from all
Allow from 192.13.237.14

Deny access from a specific IP address (for example, 192.13.237.14):

Order allow deny
Allow from all
Deny from 192.13.237.14

Blocking a group of files by mask:

<Files "\ . ( Inc | sql | others Extensions ) $ ">
Order allow, deny
Deny from all
</ Files>

In this example , the Apache web server itself can access files with the specified extensions.

You can set a ban on a specific file by its full name ( for example , config.inc.php ):

<Files config.inc.php >
Order allow , deny
Deny from all
</ Files>

Password on Directory :

AuthName "Private zone"
AuthType Basic
AuthUserFile / pub / home / login . Htpasswd
Require valid-user
</ Files>

The value AuthName will be displayed for the visitor and can be used to explain the authorization request. The AuthUserFile value indicates the location where the password file is stored to access this directory. This file is created by the special utility htpasswd.exe.

For example, in the directory that we protect by creating a password. Htaccess with the following content:

AuthName "For Registered Users Only"
AuthType Basic
AuthUserFile / pub / home / yoursite.ru/.htpasswd
Require valid-user
</ Files>

In this example, when a user requests a directory, the visitor will see the phrase " For Registered Users Only ", the password file must be in the / pub / yoursite.ru / directory and be named. Htapasswd . The directory is specified from the root of the server. If you incorrectly specify a directory, Apache will not be able to read the file. Htpasswd and no one will get access to this directory.

Similarly to protecting an entire directory, you can set a password for only one file. For example, to protect the private.zip file, it is necessary in the file. Htaccess indicate the following information:

<Files private.zip >
AuthName "Users zone"
AuthType Basic
AuthUserFile / pub / home / login . Htpasswd
</ Files>

Similarly, using the < Files > \. ( Inc | sql | other extensions) $ "> command, you can specify passwords for the file mask. For example, to set a password for access to all files with an extension. Sql you need to specify the following information:

<Files "\ . ( Sql ) $">
AuthName "Users zone"
AuthType Basic
AuthUserFile / pub / home / yoursite.ru/.htpasswd
</ Files>

In order to make the visitor's redirections to the site http://www.site.ru, c. Htaccess you must specify:

Redirect / http://www.site.ru

To be continued...