kvz.io
Published on

Control Cache Expire Dates Using Htaccess

Authors
  • avatar
    Name
    Kevin van Zonneveld
    Twitter
    @kvz

If you're running Squid to cache your website, you can use an htaccess file to control what kind of files should be cached, and for how long.

Prerequisites

First you should enable mod_expires, the Apache module that can control the Expire HTTP header in server responses:

$ a2enmod expires

htaccess

Next create a .htaccess file in your web root, containing:

ExpiresActive On
ExpiresDefault "access plus 4 hours"
ExpiresByType application/javascript A900
ExpiresByType application/x-javascript A900
ExpiresByType text/javascript A900
ExpiresByType text/html A90
ExpiresByType text/xml A90
ExpiresByType text/css A900
ExpiresByType text/plain A62
ExpiresByType image/gif A14400
ExpiresByType image/jpg A14400
ExpiresByType image/jpeg A14400
ExpiresByType image/png A14400
ExpiresByType image/bmp A14400
ExpiresByType application/x-shockwave-flash A3600

And that's it! Play around a bit with the values to suit your needs.

Legacy Comments (5)

These comments were imported from the previous blog system (Disqus).

sibirya
sibirya·

thanks a lot

davarciforum
davarciforum·

thanks a lot

アダルト無料動画
アダルト無料動画·

Thank you so much for sharing this great tip.

Kev van Zonneveld
Kev van Zonneveld·

@ アダルト無料動画: My pleasure :)

Roch
Roch·

gave this a try (im using joom la) didnt get it to work... let me know if theres something different that needs to be done.