htaccess
What is .htaccess?
.htaccess is a file that can be changed settings on the server and allows you to perform many functions, the most popular of which are:
- Setting your own 404 error page;
- Display the file listing within protected directories;
- Ban IP addresses;
- Change defoultnata index page by setting another file to be used as an index file and others.
Each version of the Apache Web server supports .htaccess
How do I make .htaccess file?
Open any editor, such as Notepad and create a file. Virtually no file name and extension only after the point, which is htaccess - this is the reason that may pose some difficulties in some cases, as some operating systems will not see it.
If you fail to create the file, give this text it another way, for example htaccess.txt, upload it to the host and then rename it via FTP program.
The syntax of commands in .htaccess must be absolutely correct, otherwise the file will not fulfill its purpose.
Most often using .htaccess
Most often file is used to set its own 404 error page.
The command syntax is:
ErrorDocument errornumber /page.html
For example:
ErrorDocument 404 /notfound.html
or
ErrorDocument 404 errorfolder / notfound.html
in the event that the file is not in the root directory.
Other commands .htaccess
- Ban on display of files and folders: Options -Indexes
- Allow to display files and folders: Options + Indexes
- Ban-ing IP addresses: deny from hhh.hhh.hhh.hhh where hhh.hhh.hhh.hhh is forbidden IP address.
At ban multiple IP addresses are displayed deny from each separately. With one command deny from may ban-not the entire address field. For this purpose must be specified only the first three numbers of the IP address and to put a point behind them: "hhh.hhh.hhh."
Ban all visitors: deny from all
- Allow access to any / and IP address / s: allow from hhh.hhh.hhh.hhh
- Set the alternative index file. When you do not want the index to be index.html or index.htm can set any file as an index using the command: DirectoryIndex file as the place to put the desired file index file, for example:
DirectoryIndex index.php
or
DirectoryIndex index2.html
or
DirectoryIndex index.php4
or
DirectoryIndex mypage.pl
or
DirectoryIndex index.wml etc.
Can be set as alternative and multiple files, for example:
DirectoryIndex index.php mypage.pl index2.html index.htm index.wml
in which case the server will check a row from left to right which of the files exists to show it as an index.
There are no restrictions for setvane of index file - if you have a file primeren.prm can set it as an index by DirectoryIndex primeren.prm
- Set the html files to be treated as php files:
AddType application / x-httpd-php .html
- Redirections via .htaccess
It is possible that an entire directory of a site / as mydir / be redirections to other directory from another site / as mynewdir site mynewsite.com/:
Redirect / mydir http://www.mynewsite.com/mynewdir
- Disable safe_mode via .htaccess:
AddType application / x-httpd-php4 .php
These are just some of the capabilities of .htaccess file. More information about the use of .htaccess can find the materials at the following address:
http://httpd.apache.org/docs/1.3/howto/htaccess.html