Skip to content

Instantly share code, notes, and snippets.

@MikeTatsky
Forked from hans2103/.htaccess-mod_headers
Created November 24, 2016 12:24
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 MikeTatsky/38e43138a8b1979a5514c6534136010f to your computer and use it in GitHub Desktop.
Save MikeTatsky/38e43138a8b1979a5514c6534136010f to your computer and use it in GitHub Desktop.
.htaccess rules to set cache control.
<IfModule mod_headers.c>
Header set Connection keep-alive
# Cache-control headers
# 2 HOURS
#<filesMatch "*">
Header set Cache-Control "max-age=7200, must-revalidate"
#</filesMatch>
# 480 weeks - 290304000
# 2 WEEKS
<filesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|swf)$">
Header set Cache-Control "max-age=1209600, public"
</filesMatch>
# 1 DAY
<filesMatch "\.(css)$">
Header set Cache-Control "max-age=86400, public, must-revalidate"
#Header set Cache-Control "max-age=0, public, must-revalidate"
</filesMatch>
# 2 DAYS
<filesMatch "\.(xml|txt)$">
Header set Cache-Control "max-age=172800, public, must-revalidate"
</filesMatch>
# 2 HOURS
<filesMatch "\.(html|htm)$">
Header set Cache-Control "max-age=7200, must-revalidate"
</filesMatch>
<FilesMatch "\.(gif|jpg|png|ico|css|js|pdf|txt)$">
Header append Cache-Control "public"
</FilesMatch>
</IfModule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment