Skip to content

Instantly share code, notes, and snippets.

@bhollis
Created March 25, 2012 22:58
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save bhollis/2200790 to your computer and use it in GitHub Desktop.
Save bhollis/2200790 to your computer and use it in GitHub Desktop.
Serving pre-gzipped assets from Apache
AddEncoding gzip .gz
RewriteEngine on
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{HTTP_USER_AGENT} !Konqueror
RewriteCond %{REQUEST_FILENAME}.gz -f
RewriteRule ^(.*)\.css$ $1.css.gz [QSA,L]
RewriteRule ^(.*)\.js$ $1.js.gz [QSA,L]
RewriteRule ^(.*)\.html$ $1.html.gz [QSA,L]
@up209d
Copy link

up209d commented Oct 30, 2017

RewriteRule ^(.*)\.css$ $1.css.gz [QSA,L]
RewriteRule ^(.*)\.js$ $1.js.gz [QSA,L]
RewriteRule ^(.*)\.html$ $1.html.gz [QSA,L]

This will cause if you don't have html.gz files => 404 Not Found, so instead, we also can combine all rewrite rules at once to:

RewriteRule ^(.*\.(css|js|html|json|svg))$ $1.gz [QSA,L]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment