Last active
May 31, 2018 16:47
-
-
Save honsa/d66b9a8265e4c1a6ed360e0b430bbbd5 to your computer and use it in GitHub Desktop.
gzip apache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> | |
<IfModule mod_deflate.c> | |
# Force compression for mangled headers. | |
# http://developer.yahoo.com/blogs/ydn/posts/2010/12/pushing-beyond-gzipping | |
<IfModule mod_setenvif.c> | |
<IfModule mod_headers.c> | |
SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding | |
RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding | |
</IfModule> | |
</IfModule> | |
# Compress all output labeled with one of the following MIME-types | |
# (for Apache versions below 2.3.7, you don't need to enable `mod_filter` | |
# and can remove the `<IfModule mod_filter.c>` and `</IfModule>` lines | |
# as `AddOutputFilterByType` is still in the core directives). | |
AddOutputFilterByType DEFLATE application/atom+xml \ | |
AddOutputFilterByType DEFLATE application/javascript \ | |
AddOutputFilterByType DEFLATE application/json \ | |
AddOutputFilterByType DEFLATE application/rss+xml \ | |
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject \ | |
AddOutputFilterByType DEFLATE application/x-font-ttf \ | |
AddOutputFilterByType DEFLATE application/x-web-app-manifest+json \ | |
AddOutputFilterByType DEFLATE application/xhtml+xml \ | |
AddOutputFilterByType DEFLATE application/xml \ | |
AddOutputFilterByType DEFLATE font/opentype \ | |
AddOutputFilterByType DEFLATE image/svg+xml \ | |
AddOutputFilterByType DEFLATE image/x-icon \ | |
AddOutputFilterByType DEFLATE text/css \ | |
AddOutputFilterByType DEFLATE text/html \ | |
AddOutputFilterByType DEFLATE text/plain \ | |
AddOutputFilterByType DEFLATE text/x-component \ | |
AddOutputFilterByType DEFLATE text/xml | |
AddOutputFilterByType DEFLATE text/javascript | |
</IfModule> | |
<IfModule mod_headers.c> | |
# Serve gzip compressed CSS files if they exist | |
# and the client accepts gzip. | |
RewriteCond "%{HTTP:Accept-encoding}" "gzip" | |
RewriteCond "%{REQUEST_FILENAME}\.gz" -s | |
RewriteRule "^(.*)\.css" "$1\.css\.gz" [QSA] | |
# Serve gzip compressed JS files if they exist | |
# and the client accepts gzip. | |
RewriteCond "%{HTTP:Accept-encoding}" "gzip" | |
RewriteCond "%{REQUEST_FILENAME}\.gz" -s | |
RewriteRule "^(.*)\.js" "$1\.js\.gz" [QSA] | |
# Serve correct content types, and prevent mod_deflate double gzip. | |
RewriteRule "\.css\.gz$" "-" [T=text/css,E=no-gzip:1] | |
RewriteRule "\.js\.gz$" "-" [T=text/javascript,E=no-gzip:1] | |
<FilesMatch "(\.js\.gz|\.css\.gz)$"> | |
# Serve correct encoding type. | |
Header append Content-Encoding gzip | |
# Force proxies to cache gzipped & | |
# non-gzipped css/js files separately. | |
Header append Vary Accept-Encoding | |
</FilesMatch> | |
#https://varvy.com/pagespeed/hsts.html | |
Header set Strict-Transport-Security "max-age=10886400; includeSubDomains; preload" | |
Header set X-XSS-Protection "1; mode=block" | |
</IfModule> | |
#block bad bots | |
BrowserMatchNoCase "HTTrack" bots | |
BrowserMatchNoCase "SEOkicks-Robot" bots | |
BrowserMatchNoCase "AhrefsBot" bots | |
BrowserMatchNoCase "Uptimebot" bots | |
BrowserMatchNoCase "Cliqzbot" bots | |
BrowserMatchNoCase "ssearch_bot" bots | |
BrowserMatchNoCase "DotBot" bots | |
BrowserMatchNoCase "seoscanners" bots | |
## EXPIRES CACHING ## | |
<IfModule mod_expires.c> | |
ExpiresActive On | |
ExpiresByType image/jpg "access plus 1 year" | |
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 2 days" | |
</IfModule> | |
## EXPIRES CACHING ## |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment