.htaccess is a configuration file for the Apache web server that allows you to manage server behavior and site settings using various directives, without modifying the main Apache configuration file.
The hosting platform uses Apache version 2.4.
Directives in .htaccess apply to the directory containing the file and all its subdirectories. If you want to change settings for the entire site, place .htaccess in the root directory: ~/your_domain/docs
1. Restricting site access by IP
Deny access from IPs 123.4.5.6 and 123.5.4.3:
Allow access only from 123.4.5.6 and 123.5.4.3:
Deny access for everyone:
2. Overriding the site’s home page (default index file)
Make menu.html the home page:
3. Enabling PHP processing in .html files
4. Enabling CGI script execution in docs folder for for files with .cgi, .pl, and .py extenstions.
Place a .htaccess file in the CGI script folder with the content:
The script must have execution rights (+x, e.g., 755). Permissions can be set via the control panel file manager, FTP client, or SSH. Also, in Web Server → Module Management («Веб-сервер» — «Управление модулями»), the CGI module must be enabled.
5. Blocking referrals from external domains
To block access from baddomain.ru to domain.ru:
To block multiple domains:
6. Using Cyrillic domains (.рф, .москва, etc.)
Cyrillic characters cannot be used in .htaccess. For redirects with Cyrillic domains, use the punycode representation. You can find the punycode of a domain using a Whois service.
Example: redirect from site.ru to сайт.рф:
In this case, visitors may see the punycode domain in the browser address bar. This is not an error.
1. Redirecting domain aliases to the main domain (301 code)
Redirect all requests to domain.ru from any domain alias:
Redirect all requests to www.domain.ru from any domain alias:
It is recommended to place these rules at the very beginning of the .htaccess file.
2. Permanent redirect (301 code)
If you changed a page address, add the following lines to .htaccess so requests from the old URL redirect to the new one:
where:
Example: redirect all requests to /period/?test=123 to domain.ru:
3. Page-by-page redirect to another domain (301 code)
The following rules will redirect all requests from your site to corresponding pages on another site. Example: A request to http://domain.ru/main will be redirected to http://www.newdomain.ru/main.
or:
4. Redirect from one page to another (301 code)
Add the following lines to .htaccess:
where:
5. Redirect for a specific IP (301 code)
Add the following lines to .htaccess:
where:
6. Redirect (301 code) from the homepage only, excluding other pages
In the .htaccess file located in the site folder that requires redirection, add:
7. Redirect (301 code) from all site pages except the homepage
In the .htaccess file located in the site folder that requires redirection, add:
8. Redirect with “mass glue”
If you need to redirect requests to index.php using .htaccess, enter:
Where site.ru is your website domain.
9. Redirect from http:// to https:// and vice versa
Redirect requests to https://domain.ru:
Redirect requests to http://domain.ru:
If after editing or adding a .htaccess file your site shows a 500 error, it most likely means there’s a mistake in the .htaccess file. To check: Rename your .htaccess file, for example, to .htaccess_old. Then test your site again. If the site works, the issue is caused by incorrect .htaccess configuration.
You can view the exact cause of the error in the log file: /var/log/your_domain.error_log
You can find detailed documentation on the official Apache web server website: http://httpd.apache.org/docs/2.4/rewrite/