<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    RewriteBase /
    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
    RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

<ifModule mod_expires.c>
ExpiresActive On

ExpiresDefault "access plus 1 days"

# Включаем кэширование изображений и флэш на месяц
ExpiresByType image/x-icon "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/webp "access plus 1 year"
ExpiresByType image/gif "access plus 43829 minutes"
ExpiresByType video/mp4 "access plus 1 year"

# Включаем кэширование css, javascript и текстовых файлоф на одну неделю
ExpiresByType text/css "access plus 1 year"
ExpiresByType text/javascript "access plus 1 year"
ExpiresByType application/javascript "access plus 1 year"
ExpiresByType application/x-javascript "access plus 1 year"

# Включаем кэширование html и htm файлов на один день
ExpiresByType text/html "access plus 43200 seconds"

# Включаем кэширование xml файлов на десять минут
ExpiresByType application/xhtml+xml "access plus 600 seconds"

# Нестандартные шрифты сайта
ExpiresByType application/x-font-ttf "access plus 1 month"
ExpiresByType font/opentype "access plus 1 month"
ExpiresByType application/x-font-woff "access plus 1 month"
ExpiresByType image/svg+xml "access plus 1 year"
ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
</ifModule>

<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE "application/atom+xml" \
                                    "application/javascript" \
                                    "application/json" \
                                    "application/ld+json" \
                                    "application/manifest+json" \
                                    "application/rdf+xml" \
                                    "application/rss+xml" \
                                    "application/schema+json" \
                                    "application/vnd.geo+json" \
                                    "application/vnd.ms-fontobject" \
                                    "application/x-font-ttf" \
                                    "application/x-javascript" \
                                    "application/x-web-app-manifest+json" \
                                    "application/xhtml+xml" \
                                    "application/xml" \
                                    "font/eot" \
                                    "font/opentype" \
                                    "image/bmp" \
                                    "image/svg+xml" \
                                    "image/vnd.microsoft.icon" \
                                    "image/x-icon" \
                                    "text/cache-manifest" \
                                    "text/css" \
                                    "text/html" \
                                    "text/javascript" \
                                    "text/plain" \
                                    "text/vcard" \
                                    "text/vnd.rim.location.xloc" \
                                    "text/vtt" \
                                    "text/x-component" \
                                    "text/x-cross-domain-policy" \
                                    "text/xml"

  <IfModule mod_setenvif.c>
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
  </IfModule>
</IfModule>

<FilesMatch "\.(ttf|otf|eot|woff|font.css)$">
  <IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin "*"
  </IfModule>
</FilesMatch>

# webfont mime types
AddType application/vnd.ms-fontobject  eot
AddType font/truetype                  ttf
AddType font/opentype                  otf
AddType application/x-font-woff        woff

# webfonts and svg:
<IfModule mod_deflate.c>
  <FilesMatch "\.(ttf|otf|eot|svg|glb)$" >
    SetOutputFilter DEFLATE
  </FilesMatch>
</IfModule>
