Skip to content

Instantly share code, notes, and snippets.

@mnoskov
Last active October 22, 2021 10:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mnoskov/65b0a033b750558d4e89251d79f3116d to your computer and use it in GitHub Desktop.
Save mnoskov/65b0a033b750558d4e89251d79f3116d to your computer and use it in GitHub Desktop.
htaccess
#redirect http to https
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTP_HOST} ^(.*)$
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
# without www all domains
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^domain\.ru$ [NC]
RewriteRule ^(.*)$ https://domain.ru/$1 [R=301,L]
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/css application/json
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE text/xml application/xml text/x-component
AddOutputFilterByType DEFLATE application/xhtml+xml application/rss+xml
AddOutputFilterByType DEFLATE application/atom+xml
AddOutputFilterByType DEFLATE image/svg+xml application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font-ttf font/opentype
AddOutputFilterByType DEFLATE application/pdf
</IfModule>
RewriteCond %{HTTP:X-HTTPS} !1
RewriteCond %{HTTP_HOST} ^(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTP_HOST} ^(.*)$
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{HTTPS} !on
RewriteCond %{HTTP_HOST} ^(.*)$
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{ENV:HTTPS} !on
RewriteCond %{HTTP_HOST} ^(.*)$
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{HTTP:CF-Visitor} '"scheme":"http"'
RewriteCond %{HTTP_HOST} ^(.*)$
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{SERVER_PORT} !^443$
RewriteCond %{HTTP_HOST} ^(.*)$
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
# 1C
#redirect http to https
RewriteCond %{HTTP:X-HTTPS} !1
RewriteCond %{REQUEST_URI} !^/export/exchange1c.php$
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTP:X-HTTPS} 1 [NC]
RewriteCond %{REQUEST_URI} ^/export/exchange1c.php$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]
<ifModule mod_headers.c>
<FilesMatch "\.(js|css|txt|ico|gif|jpg|jpeg|png|ttf|woff|woff2|svg|eot)$">
Header set Cache-Control "max-age=2592000"
</FilesMatch>
</IfModule>
<IfModule mod_expires.c>
ExpiresActive on
ExpiresDefault "access plus 1 month"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType video/ogg "access plus 1 year"
ExpiresByType audio/ogg "access plus 1 year"
ExpiresByType video/mp4 "access plus 1 year"
ExpiresByType video/webm "access plus 1 year"
ExpiresByType text/x-component "access plus 1 year"
<FilesMatch \.(eot|ttf|otf|svg|woff)$>
ExpiresDefault "access plus 1 year"
</FilesMatch>
ExpiresByType application/x-font-ttf "access plus 1 year"
ExpiresByType font/opentype "access plus 1 year"
ExpiresByType application/x-font-woff "access plus 1 year"
ExpiresByType image/svg+xml "access plus 1 year"
<FilesMatch \.(css|js)$>
ExpiresDefault "access plus 1 year"
</FilesMatch>
ExpiresByType text/css "access plus 1 year"
ExpiresByType application/javascript "access plus 1 year"
</IfModule>
php_flag zlib.output_compression On
php_value zlib.output_compression_level 5
<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 handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment