Идеальный .htaccess

ErrorDocument 404 /404.php

<ifModule mod_rewrite.c>

    RewriteEngine On

    # переадресация www.domain.com -> domain.com
    RewriteCond %{HTTP_HOST} .
    RewriteCond %{HTTP_HOST} ^www.(.*)$ [NC]
    RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

    # переадресация domain.com -> www.domain.com
    #RewriteCond %{HTTP_HOST} !^$
    #RewriteCond %{HTTP_HOST} !^www\. [NC]
    #RewriteCond %{HTTP_HOST} (.+)$
    #RewriteRule ^(.*)$ https://www.%1/$1 [R=301,L] .

    # переадресация на https кроме robots.txt и sitemap.xml
    RewriteCond %{SERVER_PORT} !^443$
    RewriteCond %{REQUEST_URI} !^/robots.txt
    RewriteCond %{REQUEST_URI} !^/sitemap.xml
    RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

</ifModule>

<ifModule mod_expires.c>

    # Add correct content-type for fonts
    AddType application/vnd.ms-fontobject .eot
    AddType application/x-font-ttf .ttf
    AddType application/x-font-opentype .otf
    AddType application/x-font-woff .woff
    AddType image/svg+xml .svg
    AddType application/json .json

    # Compress compressible fonts
    AddOutputFilterByType DEFLATE application/x-font-ttf application/x-font-opentype image/svg+xml

    ExpiresActive On
    ExpiresDefault "access plus 5 seconds"

    # Cache Images
    ExpiresByType image/x-icon "access plus 2592000 seconds"
    ExpiresByType image/jpeg "access plus 2592000 seconds"
    ExpiresByType image/png "access plus 2592000 seconds"
    ExpiresByType image/gif "access plus 2592000 seconds"
    ExpiresByType image/svg+xml "access plus 2592000 seconds"

    # Cache Fonts
    ExpiresByType application/vnd.ms-fontobject "access plus 2592000 seconds"
    ExpiresByType application/x-font-ttf "access plus 2592000 seconds"
    ExpiresByType application/x-font-opentype "access plus 2592000 seconds"
    ExpiresByType application/x-font-woff "access plus 2592000 seconds"
    ExpiresByType image/svg+xml "access plus 2592000 seconds"

    # Cache other content types (Flash, CSS, JS, HTML, XML)
    ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds"
    ExpiresByType text/css "access plus 604800 seconds"
    ExpiresByType text/javascript "access plus 2592000 seconds"
    ExpiresByType application/javascript "access plus 2592000 seconds"
    ExpiresByType application/x-javascript "access plus 2592000 seconds"
    ExpiresByType application/json "access plus 2592000 seconds"
    ExpiresByType text/html "access plus 600 seconds"
    ExpiresByType application/xhtml+xml "access plus 600 seconds"

</ifModule>

<ifModule mod_deflate.c>

    AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/css text/javascript application/javascript application/x-javascript application/json

</ifModule>

На главную