.htaccess overview
Common configuration examples for the .htaccess file.
.htaccess is an Apache web server configuration file that lets you define settings and access rules for individual directories without modifying the main server configuration. It can be used to control access to files and directories, set up redirects, define character encoding, remap file types, and more.
The file is read by Apache on every request, so changes take effect immediately.
Examples
Block access to the site for everyone:
Deny from all
Block access from a specific IP address:
Order Allow,Deny
Allow from all
Deny from 111.111.111.111
Allow access only from a specific IP address:
Order Deny,Allow
Deny from all
Allow from 111.111.111.111
Redirect HTTP to HTTPS:
RewriteEngine on
RewriteCond %{ENV:HTTPS} !on
RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Redirect HTTPS to HTTP:
RewriteEngine on
RewriteCond %{ENV:HTTPS} on
RewriteRule ^.*$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Our products and services
Force a specific character encoding:
AddDefaultCharset windows-1251
Custom error pages:
ErrorDocument 401 http://site.ru/errors/401.html
ErrorDocument 403 http://site.ru/errors/403.html
ErrorDocument 404 http://site.ru/errors/404.html
ErrorDocument 500 http://site.ru/errors/500.html
The error page files (401.html, 403.html, etc.) must be present in the specified directory.
Enable PHP processing in .html files:
<IfModule mime_module>
AddType application/x-httpd-ea-php56 .php .php5 .phtml .htm .html
</IfModule>
Replace x-httpd-ea-php56 with your current PHP version. For example, for PHP 5.3 use x-httpd-ea-php53.
Changing PHP settings via
.htaccessis not available on shared hosting.
Further reading:
Help
If you have any questions or need assistance, please contact us through the ticket system — we're always here to help!