.htaccess - стандартные правила
Последние записи
Правила .htaccess для стандартного проекта Битрикс
Options -Indexes
ErrorDocument 404 /404.php
<IfModule mod_headers.c>
# Все html и htm файлы будут храниться в кэше браузера один день
<FilesMatch "\.(html|htm)$">
Header set Cache-Control "max-age=1"
</FilesMatch>
# Все css, javascript и текстовые файлы будут храниться в кэше браузера одну неделю
<FilesMatch "\.(js|css|txt)$">
Header set Cache-Control "max-age=2592000"
</FilesMatch>
# Все флэш файлы и изображения будут храниться в кэше браузера одну неделю
<FilesMatch "\.(flv|swf|ico|gif|jpg|jpeg|png|webp)$">
Header set Cache-Control "max-age=2592000"
</FilesMatch>
# Отключаем кеширование php и других служебных файлов
<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>
#Отключение любого кеширования, на всякий случай
#<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>
Отличный материал по редиректам 301 редирект (переадресация) через .htaccess – на все случаи жизни
Исключаем папку из правил обработки ЧПУ Битрикс
Перед строчкой RewriteRule ^(.*)$ /bitrix/urlrewrite.php [L]
вставляем следующее правило:
RewriteCond %{REQUEST_URI} !^/FOLDER_EXCLUDE/.*$
Комментарии