18

I am trying to configure my .htaccess file to set the cache time. Tried 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 including 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

1 Answer 1

52

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.

Sign up to request clarification or add additional context in comments.

2 Comments

seems that mod_headers.c is turned off. I'll have to send a request to open to the sysadmin. Why is mod_headers.c preffered over mod_expires.c?
Ok, seem to figure something out... Very strange, but see,s that A3720 means a zero. Thus, if I want an expiration of 10min, I have to wrote 3720+600 i.e 4320. This explains why "A3600" did not work. However, does anyone knows why is the zero line is 3720?!?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.