Konfigurirovanie a site with the help of a file .htaccess
Web - Apache server is a powerful and multipurpose software product with various opportunities. In given clause{article} will be rasmotreny receptions konfigurirovanija Apache, most often meeting at development Web - sites.
As is known, all adjustments of Apache server are in fajle httpd.conf, access to which is present not always. For example, if the virtual server on a hosting when one Apache server serves hundreds sites is used, that, naturally, is impossible to allow for the owner of one site to change a configuration of the server which will be reflected in all other sites. Nevertheless Web - Apache server supposes konfigurirovanie at a level of separate catalogues by means of files .htaccess. on job with these files as unique configuration files which are accessible to majority Web - developers, and will make the basic emphasis in this clause{article}.
The file .htaccess (with a point in the beginning of a name) is a configuration file which enables to adjust job of the server at a level of separate catalogues: to establish access rights to files in catalogues, to change names of index files, independently to process codes of answers of report HTTP, to modify addresses of the requested pages.
The note
The file .htaccess can be placed in any catalogue. Directives of this file operate on all files in the current catalogue and in all his{its} subdirectories (if these directives are not redefined by directives of files .htaccess in the enclosed catalogues).
The changes brought in files .htaccess, inure immediately and do not demand perezagruzki the server as against the changes brought in the main configuration file httpd.conf.
That files .htaccess could be used, corresponding adjustments of the main configuration file httpd.conf where directives which will allow .htaccess to redefine to a file a configuration of the Web-server in the catalogue should be registered are necessary. The list of these directives is set by AllowOverride directive.
AllowOverride directive can include one of the following directives or their combination: AuthConfig, FileInfo, Indexes, Limit, Options, All, None
To give directives of files .htaccess the maximal rights on changes of directives, value of AllowOverride directive in a file httpd.conf it should be equal All. It is a default value.
AllowOverride All
To forbid redefinition of any directives in configuration files .htaccess it is possible by means of value None:
AllowOverride None
The remark
The name of a configuration file can be changed, and for example, to name it{him} not .htaccess, a access.conf. For the name of this file AccessFileName directive in a file httpd.conf responds. Change of the name of a configuration file .htaccess is not recommended, since it can complicate the further support of the server.
Syntax .htaccess
Before examples will be considered, we shall stop on syntax of directives in files .htaccess.
? Ways to files and catalogues should be specified from a root of the server, for example,/pub/articles/masters/php/
? At the instruction{indication} absolute url necessarily should be zaadany reports, for example: Redirect / http://www.site.ru <http: // www.internet-technologies.ru/? url=http%3A%2F%2Fwww.site.ru>
? In files .htaccess blanks in instructions{indications} of ways to files and in names of files since it results in generation of a code of the answer 500 - a mistake of a configuration of the server are invalid: " Internal Server Error ".
Examples of use .htaccess
Index pages:
There can be situations when it is necessary to change structure of index files, for example, if the index page index.php is necessary, and in the basic configuration file httpd.conf she is not registered. This problem{task} can be solved by means of a file .htaccess in which it is necessary to create DirectoryIndex directive where names of index pages will be listed:
DirectoryIndex index.php index.shtml index.html
At search of the catalogue without the instruction{indication} of a name of a file search of page with a name index.php all over again will be carried out. If the page with such name no in the catalogue similar operations will be made with a file index.shtml, etc. up to the end of the list, the corresponding page will not be found and open yet.
Interdiction on display of contents of the catalogue at absence of an index file
Often it is required to forbid display of the list of files in the catalogue if not it is specified or there is no index file. For example, to forbid display of contents of the catalogue with images. If such interdiction to not put the user who has addressed directly to such catalogue, will receive the list of all images.

|