Search code examples
apachecachinghttp-caching

Setting cache-control max-age using Apache not working


I'm trying to setup HTTP Caching for my website. Following is my configuration settings

# 1 YEAR
<FilesMatch "\.(ico|svg|woff|eot|ttf)$">
Header set Cache-Control "max-age=31536000, public"
</FilesMatch>

# 1 WEEK
<FilesMatch "\.(jpg|png|gif|css|js)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>

Does it make a difference if I place this in my <VirtualHost> settings or outside it? I've placed it inside the <VirtualHost>.

I tried checking the HTTP response for one of the png image using redbot.org and this is what it returned.

HTTP/1.1 200 OK
    Date: Fri, 12 Sep 2014 09:28:33 GMT
    Server: Apache/2.4.7 (Ubuntu)
    Last-Modified: Tue, 26 Aug 2014 05:43:32 GMT
    ETag: 1409031812.69
    Content-Length: 23907
    Keep-Alive: timeout=5, max=100
    Connection: Keep-Alive
    Content-Type: image/png

Why is there no Cache-Control max-age header tag?

I also checked using the Google PageSpeed Insights and it still says expiration not specified for all the files.

Did I miss something?


Solution

  • The .htaccess file was not being taken into account due to some missing configuration settings in my apache2.conf file. Making the required changes in the conf file solved the issue.