.htaccess - configuration file of the Apache web server. It allows you to set a large number of additional parameters and permissions for the web server in individual directories (folders), such as controlling access to directories and files, reassigning file types, specifying encoding, etc., without changing the main configuration file
The .htaccess file is read by the Apache web server each time it is accessed, so all changes take effect immediately after the change.
Examples of using .htaccess file
Restricting access to the site for everyone:*
Deny from all
Restrict access to the site from IP-address 111.111.111.111:*
Order Allow,Deny
Allow from all
Deny from 111.111.111.111
Restrict access to the site from all addresses except 111.111.111.111:*
Order Deny,Allow
Deny from all
Allow from 111.111.111.111
Redirect from HTTP to HTTPS and back:*
Redirect requests to https://site.ru
RewriteEngine on
RewriteCond %{ENV:HTTPS} !on
RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Redirect requests to http://site.ru
RewriteEngine on
RewriteCond %{ENV:HTTPS} on
RewriteRule ^.*$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Pressure encoding:
AddDefaultCharset windows-1251
Use your own generic error pages, for example, somehow the most commonly used ones:
* 401 Authorization Required
ErrorDocument 401 http://site.ru/errors/401.html
* 403 Forbidden - Access Denied
ErrorDocument 403 http://site.ru/errors/403.html
* 404 Not Found - Document Not Found
ErrorDocument 404 http://site.ru/errors/404.html
* 500 Internal Server Error
ErrorDocument 500 http://site.ru/errors/500.html
Corresponding files of error pages (401.html, 404.html, etc.) must be in root directory of the site.
Include PHP processing in .html files
``apache
AddType application/x-httpd-ea-php56 .php .php5 .phtml .htm .html
```
Where x-httpd-ea-php56 - you must specify the current version of PHP. For example, for PHP version 5.3, you should specify x-httpd-ea-php53.
Also draw your attention to the fact that we can not change the settings of php through .htaccess*
You can read more about the .htaccess configuration file at the following links