» Control cache expire dates using htaccess

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.

Stay up to date

You can track my blog rss articles and rss comments. You may also find my rss bookmarks interesting. Or twitter Follow me on Twitter


Like this article?

   Then Digg it!
Or use another bookmark button below to show your support &
help me spread the word.


tags: squid, htaccess, virtual host, apache, mod_expires
category: Howto - Webserver
read: 10,125 times

Add comment

(required, shown)(required, not shown)for syntax highlighting

[CODE="Javascript"]
your_code_here();
[/CODE]

Replace "Javascript"
with "php", "text", etc.
code (to make sure you are not a spammer)

 Track replies: rss feed comments feed

Comments

#2. davarciforum on 14 October 2008

Gravatar.com: davarciforumthanks a lot

#1. sibirya on 28 August 2008

Gravatar.com: sibiryathanks a lot