.htaccess - standard rules
The last notes
All English-language materials have been translated fully automatically using the Google service
.htaccess rules for the standard Bitrix project
Options -Indexes
ErrorDocument 404 /404.php
<IfModule mod_headers.c>
# All html and htm files will be stored in the browser cache for one day
<FilesMatch "\. (Html | htm) $">
Header set Cache-Control "max-age = 1"
</FilesMatch>
# All css, javascript and text files will be stored in the browser cache for one week
<FilesMatch "\. (Js | css | txt) $">
Header set Cache-Control "max-age = 2592000"
</FilesMatch>
# All flash files and images will be stored in the browser cache for one week
<FilesMatch "\. (Flv | swf | ico | gif | jpg | jpeg | png|webp) $">
Header set Cache-Control "max-age = 2592000"
</FilesMatch>
# Disable caching php and other service files
<FilesMatch "\. (Pl | php | cgi | spl | scgi | fcgi) $">
Header unset Cache-Control
</FilesMatch>
</IfModule>
<IfModule mod_deflate.c>
# Выставляем заголовок Content-Encoding: gzip.
AddEncoding gzip .gz
# Для favicon.ico
AddOutputFilterByType DEFLATE image/x-icon
# Для CSS-файлов.
AddOutputFilterByType DEFLATE text/css
# Для JavaScript-файлов.
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/json
# Для остальных типов файлов.
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/x-component
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/atom+xml
AddOutputFilterByType DEFLATE font/truetype
AddOutputFilterByType DEFLATE font/opentype
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE image/svg+xml
# Отключаем сжатие для тех браузеров, у которых проблемы
# с его распознаванием.
BrowserMatch "MSIE [456]" no_gzip dont-vary
BrowserMatch "SV1;" !no_gzip !dont-vary
BrowserMatch "Opera" !no_gzip !dont-vary
BrowserMatch "Firefox/[0-3]\." gzip-only-text/html
BrowserMatch "Firefox/3\.[1-9]" !gzip-only-text/html
BrowserMatch "Chrome/2" gzip-only-text/html
BrowserMatch "Safari" gzip-only-text/html
BrowserMatch "Konqueror" gzip-only-text/html
</IfModule>
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_include mime ^text/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_include handler ^cgi-script$
</ifModule>
<IfModule mod_php5.c>
php_flag allow_call_time_pass_reference 1
php_flag session.use_trans_sid off
#php_value display_errors 1
#php_value mbstring.internal_encoding UTF-8
</IfModule>
<IfModule mod_rewrite.c>
Options + FollowSymLinks
RewriteEngine On
#Redirect http => https
RewriteCond% {HTTPS}! = On
RewriteRule ^ (. *) $ Https: //% {HTTP_HOST} / $ 1 [R = 301, L]
#Redirect http => https reserve option
#RewriteCond% {SERVER_PORT}! ^ 443 $
#RewriteRule ^ (. *) $ Https://mysite.ru/$1 [R = 301, L]
#Redirect www => not www
RewriteCond% {REQUEST_URI}! \?
RewriteCond% {REQUEST_URI}! \ &
RewriteCond% {REQUEST_URI}! \ =
RewriteCond% {REQUEST_URI}! \.
RewriteCond% {REQUEST_URI}! [^ \ /] $
RewriteCond% {HTTP_HOST} ^ www \. (. *) $
RewriteRule ^ (. *) $ Https: //% 1 / $ 1 [L, R = 301]
#Redirect not / => /
RewriteCond% {REQUEST_URI}! \?
RewriteCond% {REQUEST_URI}! \ &
RewriteCond% {REQUEST_URI}! \ =
RewriteCond% {REQUEST_URI}! \.
RewriteCond% {REQUEST_URI}! \ / $
RewriteCond% {HTTP_HOST} ^ ([^ www]. *) $
RewriteRule ^ (. *) $ Https: //% 1 / $ 1 / [L, R = 301]
#Standart rules
RewriteCond% {REQUEST_FILENAME}! -F
RewriteCond% {REQUEST_FILENAME}! -L
RewriteCond% {REQUEST_FILENAME}! -D
RewriteCond% {REQUEST_FILENAME}! /Bitrix/urlrewrite.php$
RewriteRule ^ (. *) $ /Bitrix/urlrewrite.php [L]
RewriteRule. * - [E = REMOTE_USER:% {HTTP: Authorization}]
</IfModule>
<IfModule mod_dir.c>
DirectoryIndex index.php index.html
</IfModule>
<IfModule mod_expires.c>
ExpiresActive on
ExpiresDefault "access plus 1 month"
# CSS
ExpiresByType text/css "access plus 1 year"
# Data interchange
ExpiresByType application/atom+xml "access plus 1 hour"
ExpiresByType application/rdf+xml "access plus 1 hour"
ExpiresByType application/rss+xml "access plus 1 hour"
ExpiresByType application/json "access plus 0 seconds"
ExpiresByType application/ld+json "access plus 0 seconds"
ExpiresByType application/schema+json "access plus 0 seconds"
ExpiresByType application/vnd.geo+json "access plus 0 seconds"
ExpiresByType application/xml "access plus 0 seconds"
ExpiresByType text/xml "access plus 0 seconds"
# Favicon (cannot be renamed!) and cursor images
ExpiresByType image/vnd.microsoft.icon "access plus 1 week"
ExpiresByType image/x-icon "access plus 1 week"
# HTML
ExpiresByType text/html "access plus 0 seconds"
# JavaScript
ExpiresByType application/javascript "access plus 1 year"
ExpiresByType application/x-javascript "access plus 1 year"
ExpiresByType text/javascript "access plus 1 year"
# Manifest files
ExpiresByType application/manifest+json "access plus 1 year"
ExpiresByType application/x-web-app-manifest+json "access plus 0 seconds"
ExpiresByType text/cache-manifest "access plus 0 seconds"
#Media files
ExpiresByType audio/ogg "access plus 3 month"
ExpiresByType image/bmp "access plus 3 month"
ExpiresByType image/gif "access plus 3 month"
ExpiresByType image/jpeg "access plus 3 month"
ExpiresByType image/png "access plus 3 month"
ExpiresByType image/svg+xml "access plus 3 month"
ExpiresByType image/webp "access plus 3 month"
ExpiresByType video/mp4 "access plus 3 month"
ExpiresByType video/ogg "access plus 3 month"
ExpiresByType video/webm "access plus 3 month"
#Web fonts
# Embedded OpenType (EOT)
ExpiresByType application/vnd.ms-fontobject "access plus 3 month"
ExpiresByType font/eot "access plus 3 month"
# OpenType
ExpiresByType font/opentype "access plus 3 month"
# TrueType
ExpiresByType application/x-font-ttf "access plus 3 month"
# Web Open Font Format (WOFF) 1.0
ExpiresByType application/font-woff "access plus 3 month"
ExpiresByType application/x-font-woff "access plus 3 month"
ExpiresByType font/woff "access plus 3 month"
# Web Open Font Format (WOFF) 2.0
ExpiresByType application/font-woff2 "access plus 3 month"
# Other
ExpiresByType text/x-cross-domain-policy "access plus 1 week"
# Others
ExpiresByType application/pdf "access plus 3 month"
ExpiresByType application/x-shockwave-flash "access plus 3 month"
</IfModule>
# Disable any caching, just in case
# <filesMatch "\. (php | html | htm | js | css) $">
# FileETag None
# <ifModule mod_headers.c>
# Header unset ETag
# Header set Cache-Control "max-age = 0, no-cache, no-store, must-revalidate"
# Header set Pragma "no-cache"
# Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
# </ifModule>
# </filesMatch>
Great stuff on redirects 301 redirects via .htaccess - for all occasions
Excluding the folder from the Bitrix CNC processing rules
Before the line RewriteRule ^ (. *) $ /bitrix/urlrewrite.php [L]
insert the following rule:
RewriteCond %{REQUEST_URI} !^/FOLDER_EXCLUDE/.*$
Comments