VerbAlexVlad
@VerbAlexVlad
Программист-любитель

Как правильно настроить .htacess?

Пытаюсь довести до ума .htaccess.
Протестировал его на сайте https://htaccess.madewithlove.com/ и там куча предупреждений. Но что они значат и как должно быть правильно не знаю.

Друзья, помогите настроить его грамотно (сайт tvtshop.ru)
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
RewriteCond  %{HTTP_HOST} tvtshop.ru$
RewriteRule ^robots.txt$ web/robots.txt [L]
RewriteRule .* - [E=HTTP_IF_MODIFIED_SINCE:%{HTTP:If-Modified-Since}]
RewriteRule .* - [E=HTTP_IF_NONE_MATCH:%{HTTP:If-None-Match}]

RewriteCond %{REQUEST_URI} !^/(web)
RewriteCond %{HTTP_HOST} !^www\.tvtshop\.ru$ [NC]
RewriteCond %{HTTP:X-Forwarded-Proto} !=https
RewriteRule ^(.*)$ https://www.tvtshop.ru/$1 [R=301,L]


RewriteRule ^assets/(.*)$ /web/assets/$1 [L]
RewriteRule ^css/(.*)$ web/css/$1 [L]
RewriteRule ^fonts/(.*)$ web/fonts/$1 [L]
RewriteRule ^js/(.*)$ web/js/$1 [L]
RewriteRule ^images/(.*)$ web/images/$1 [L]
RewriteRule ^upload/(.*)$ web/upload/$1 [L]
RewriteRule (.*) /web/$1

## Перенаправление с http на https
# <IfModule mod_rewrite.c>
# RewriteCond %{HTTPS} =off
# RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [QSA,L]
# </IfModule>

# кеширование в браузере на стороне пользователя
<IfModule mod_expires.c>
# Fonts
# Add correct content-type for fonts


ExpiresActive on
    AddType application/font-sfnt                       otf ttf
    AddType application/font-woff                       woff
    AddType application/font-woff2                      woff2
    AddType application/vnd.ms-fontobject               eot

    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 1 month"
    ExpiresByType image/bmp                             "access plus 1 month"
    ExpiresByType image/gif                             "access plus 1 month"
    ExpiresByType image/jpeg                            "access plus 1 month"
    ExpiresByType image/png                             "access plus 1 month"
    ExpiresByType image/svg                             "access plus 1 month"
    ExpiresByType image/svg+xml                         "access plus 1 month"
    ExpiresByType image/webp                            "access plus 1 month"
    ExpiresByType video/mp4                             "access plus 1 month"
    ExpiresByType video/ogg                             "access plus 1 month"
    ExpiresByType video/webm                            "access plus 1 month"

  # Web fonts

    # Embedded OpenType (EOT)
    ExpiresByType application/vnd.ms-fontobject         "access plus 1 month"
    ExpiresByType font/eot                              "access plus 1 month"

    # OpenType
    ExpiresByType font/opentype                         "access plus 1 month"

    # TrueType
    ExpiresByType application/x-font-ttf                "access plus 1 month"

    # Web Open Font Format (WOFF) 1.0
    ExpiresByType application/font-woff                 "access plus 1 month"
    ExpiresByType application/x-font-woff               "access plus 1 month"
    ExpiresByType font/woff                             "access plus 1 month"
    ExpiresByType application/font-sfnt                 "access plus 1 month"

    # Web Open Font Format (WOFF) 2.0
    ExpiresByType application/font-woff2                "access plus 1 month"

  # Other
    ExpiresByType text/x-cross-domain-policy            "access plus 1 week"
    ExpiresByType application/x-font-ttf                "access plus 1 year"
    ExpiresByType application/x-font-opentype           "access plus 1 year"
</IfModule>



# Cache-Control
<ifModule mod_headers.c>
# 30 дней
<filesMatch "\.(ico|pdf|flv|jpg|JPG|jpeg|png|gif|swf|svg|webp)$">
Header set Cache-Control                                "max-age=31536000, public"
</filesMatch>
# 30 дней
<filesMatch "\.(woff|woff)$">
Header set Cache-Control                                "max-age=2592000, public"
</filesMatch>
# 30 дней
<filesMatch "\.(css|js)$">
Header set Cache-Control                                "max-age=2592000, public"
</filesMatch>
# 30 дней
<filesMatch "\.(js)$">
Header set Cache-Control                                "max-age=2592000, public"
</filesMatch>
# 2 дня
<filesMatch "\.(woff|woff2|ttf|svg|eot|otf)$">
Header set Cache-Control                                "max-age=31536000, public"
</filesMatch>
# 1 день
<filesMatch "\.(html|htm|php)$">
Header set Cache-Control                                "max-age=172800, private, must-revalidate"
</filesMatch>
</ifModule>

# использование кеша браузеров
FileETag MTime Size
<ifmodule mod_expires.c>
<filesmatch ".(jpg|jpeg|gif|png|ico|css|js)$">
ExpiresActive on
  ExpiresByType image/jpg                               "access plus 1 year"
  ExpiresByType image/webp                              "access plus 1 month"
  ExpiresByType image/jpeg                              "access plus 1 year"
  ExpiresByType image/gif                               "access plus 1 year"
  ExpiresByType image/png                               "access plus 1 year"
  ExpiresByType text/css                                "access plus 1 month"
  ExpiresByType application/pdf                         "access plus 1 month"
  ExpiresByType text/x-javascript                       "access plus 1 month"
  ExpiresByType application/x-shockwave-flash           "access plus 1 month"
  ExpiresByType image/x-icon                            "access plus 1 year"
  ExpiresDefault                                        "access plus 1 month"
</filesmatch>
</ifmodule>

#Запрет отдачи HTTP-заголовков Vary браузерам семейства MSIE
<IfModule mod_setenvif.c>
BrowserMatch "MSIE" force-no-vary
BrowserMatch "Mozilla/4.[0-9]{2}" force-no-vary
</IfModule>

## Включение сжатия текста используя mod_deflate ##
# Установить mod_deflate и включить в файле (/usr/local/apache/conf/httpd.conf)
<IfModule mod_deflate.c>
<FilesMatch "\.(html|php|txt|xml|js|css)$">
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>

AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
  • Вопрос задан
  • 170 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы