How to set the Expires header with Apache 2 and mod_expires
Apache posted 11 months ago by christian
First you need to enable the mod_expires module:
1 a2enmod expires
Next add this to your configuration:
1 ExpiresActive On 2 # Set Expires header to current time by default 3 ExpiresDefault A0 4 5 <FilesMatch "\.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav)$"> 6 ExpiresDefault "access plus 30 days" 7 </FilesMatch> 8 9 <FilesMatch "\.(jpg|jpeg|png|gif|swf|bmp|)$"> 10 ExpiresDefault "access plus 7 days" 11 </FilesMatch> 12 13 <FilesMatch "\.(txt|xml|js|css)$"> 14 ExpiresDefault "access plus 1 day" 15 </FilesMatch>
Now restart Apache:
1 $ sudo /etc/init.d/apache2 force-reload
Check that the proper headers are set with Firebug, Yahoo YSlow or Google Page speed.