AddDefaultCharset utf-8
DirectoryIndex index.php
RewriteEngine On
RewriteBase /
ServerSignature Off
Options -Indexes

FileETag None
Header unset ETag

# убираем www
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
 
# Редирект для всех страниц на версию https:
#RewriteCond %{HTTPS} off
#RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# админка
RewriteRule ^admin_(.*).htm$ admin.php?module=$1 [QSA,L]
RewriteRule ^admin$ admin.htm [L,R=301,NC,NE]
RewriteRule ^admin.htm$ admin.php [QSA,L]

RewriteCond %{THE_REQUEST} /index\.php(/(.*?))? [NC]
RewriteRule ^(.*?)index\.php(/(.*?))?$ /$1$2 [L,R=301,NC,NE]

RewriteCond %{THE_REQUEST} /index\.html(/(.*?))? [NC]
RewriteRule ^(.*?)index\.html(/(.*?))?$ /$1$2 [L,R=301,NC,NE]

# убираем слеш в конце
RewriteCond %{HTTP_HOST} (.*)
RewriteCond %{REQUEST_URI} /$ [NC]
RewriteRule ^(.*)(/)$ $1 [L,R=301]

# убираем двойные слеши
RewriteCond %{THE_REQUEST} //
RewriteRule .* /$0 [R=301,L]

RewriteRule ^(.*).to-webp$ resize.php?webp=$1

php_value memory_limit 500M
php_value post_max_size 500M
php_value upload_max_filesize 500M
php_value max_file_uploads 20

<IfModule mod_headers.c>
    # Кэш на 1 год для статичных файлов (включая видео)
    <FilesMatch "\.(ico|gif|jpg|jpeg|png|svg|webp|mp4|webm|js|css|woff2|woff|ttf|eot|otf|json|xml)$">
        Header set Cache-Control "public, max-age=31536000, immutable"
    </FilesMatch>

    # Отключить кэш для PHP, HTML
    <FilesMatch "\.(php|html?|htm)$">
        Header set Cache-Control "no-store, no-cache, must-revalidate, max-age=0"
        Header set Pragma "no-cache"
        Header set Expires "0"
    </FilesMatch>
</IfModule>

<IfModule mod_expires.c>
    # Настройки по MIME-типам
	ExpiresActive On
    ExpiresDefault "access plus 1 year"
    # Изображения
    ExpiresByType image/jpeg "access plus 1 year"
    ExpiresByType image/png "access plus 1 year"
    ExpiresByType image/gif "access plus 1 year"
    ExpiresByType image/svg+xml "access plus 1 year"
    ExpiresByType image/webp "access plus 1 year"
    ExpiresByType image/x-icon "access plus 1 year"
    # Стили и скрипты
    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"
    # Шрифты
    ExpiresByType font/woff2 "access plus 1 year"
    ExpiresByType font/woff "access plus 1 year"
    ExpiresByType application/font-woff2 "access plus 1 year"
    ExpiresByType application/font-woff "access plus 1 year"
    # Видео
    ExpiresByType video/mp4 "access plus 1 year"
    ExpiresByType video/webm "access plus 1 year"
</IfModule>

<IfModule mod_deflate.c>
    # Сжатие текстовых ресурсов
    AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/xml
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE text/javascript
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/x-javascript
    AddOutputFilterByType DEFLATE application/json
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE application/xhtml+xml
    AddOutputFilterByType DEFLATE application/rss+xml
    AddOutputFilterByType DEFLATE font/woff2
    AddOutputFilterByType DEFLATE font/woff
</IfModule>

<IfModule mod_brotli.c>
    AddOutputFilterByType BROTLI_COMPRESS text/html text/plain text/xml text/css text/javascript application/javascript application/json application/xml font/woff2
</IfModule>

<FilesMatch "^(\.env|\.git|\.htaccess|composer\.json|composer\.lock)$">
  Require all denied
</FilesMatch>

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .+ - [L]

# карта сайта и RSS
RewriteRule ^sitemap.xml$ sitemap.php [QSA,L]

# редирект на index.php
RewriteRule ^(.*)$ index.php [QSA,L]
