HTTP cache headers with .htaccess

60,049

I advise you to use headers mod. You can activate it (if disabled) with this command :

a2enmod headers

Here is a simple code example that works:

<IfModule mod_headers.c>
    # WEEK
    <FilesMatch "\.(jpg|jpeg|png|gif|swf)$">
        Header set Cache-Control "max-age=604800, public"
    </FilesMatch>

    # WEEK
    <FilesMatch "\.(js|css|swf)$">
        Header set Cache-Control "max-age=604800"
    </FilesMatch>
</IfModule>

max-age is cached time in seconds.

Share:
60,049
Yura
Author by

Yura

Updated on October 23, 2020

Comments

  • Yura
    Yura over 3 years

    I am trying to configure my .htaccess file to set the cache time. Tryied every possible configuration but nothing works!

    This is what is written in my HTML:

     <meta http-equiv="Cache-Control" content="max-age=2592000, public" />
     <!--        
     <meta http-equiv="expires" content="mon, 24 sep 2012 14:30:00 GMT">
      -->
    

    and this is what written in my .htaccess file:

    ExpiresActive On
    ExpiresDefault A3600
    

    However, when I refresh inclusind cache clear (ctrl+F5) in firefox, my firebug NET panel says that the cache expires at the same second I have accessed the file ( and not in the future, as I want it to be).

    What am I doing wrong??

    Thanks