.htaccess file | Airnet

.htaccess file

ALMAZ DANAEV
CEO

The .htaccess file provides the ability to further customize the web server and achieve the following goals like:

-Restricting access to sites;

-Redirect to another domain;

-Show your own error pages;

-Changing values in PHP directives.

Redirecting from one site to another

To redirect from one site to another, you need to add the following lines to the .htaccess file:

RewriteEngine on

RewriteCond %{HTTP_HOST} ^(www\.)?from\.com$

RewriteRule ^(.*)$ http://to.com/$1 [L,R=301]

where from\.com is the domain name to be redirected from and "to.com" is the  target.

However, escaping the dot character with a backslash \ in the second line is optional.

Redirect from HTTP to HTTPS

Redirecting from HTTP protocol to HTTPS protocol is done by adding  code to the .htaccess file:

RewriteEngine on

RewriteCond %{HTTP:HTTPS} !=on [NC]

RewriteRule ^(.*)$ https://www.example.ru/$1 [R=301,L]

and vice versa, from HTTPS to HTTP:

RewriteEngine on

RewriteCond %{HTTP:HTTPS} =on [NC]

RewriteRule ^(.*)$ http://www.example.ru/$1 [R=301,L]

Restricting and allowing access to the site from certain ip-addresses

To restrict access to the site from certain IP addresses, add the following to the .htaccess file:

Order Allow,Deny

Allow from all

Deny from IP

where instead of the substring IP you need to add the IP address for which you will need to restrict access, or a list such IP addresses separated by spaces.

If you want to allow access to the site only from certain IP addresses, for this you can add the following lines:

Order Deny,Allow

Deny from all

Allow from IP

where IP is the IP address to which access will be allowed, or a space-separated list of such IP addresses.

 Restrict access to certain files

Setting  access restrictions to some files is done by adding to the .htaccess file:

<Files FILE_PATH>

Order Deny,Allow

Deny from all

Allow from IP

</Files> Where the path _to_ the file must be replaced with the target file, and IP with the IP address where   will be allowed to access it.

Go back to Knowledge Base

Did not find an answer to your question? Call our specialists by phone +998(71) 202-87-00

Our partners