.htaccess - стандартные правила

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"
    # 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"
    # 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"
    # Disable caching php and other service files
    <FilesMatch "\. (Pl | php | cgi | spl | scgi | fcgi) $">
        Header unset Cache-Control

<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/
    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 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 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 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://$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 mod_dir.c>
    DirectoryIndex index.php index.html

<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/              "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/         "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"

# 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:



There are no comments yet, you can be the first to leave it

Leave a comment

The site uses a comment pre-moderation system, so your message will be published only after approval by the moderator

You are replying to a user's comment



Email me

Are you developing a new service, making improvements to the existing one and want to be better than your competitors? You have come to the right place. I offer you a comprehensive studio-level website development. From me you can order design, layout, programming, development of non-traditional functionality, implementation of communication between CMS, CRM and Data Analitics, as well as everything else related to sites, except for promotion.

Contact, I will always advise on all questions and help you find the most effective solution for your business. I am engaged in the creation of sites in Novosibirsk and in other regions of Russia, I also work with the CIS countries. You will be satisfied with our cooperation

An error occurred while sending, please try again after a while
Message sent successfully


+7(993) 007-18-96



Россия, г. Москва

By submitting the form, you automatically confirm that you have read and accept the Privacy Policy site

Contact with me
Send message
By submitting the form, you automatically confirm that you have read and accept Privacy policy of site
Sending successful!
Thank you for contacting :) I will contact you as soon as possible
Sending failed
An error occurred while sending the request. Please wait and try again after a while or call my phone number