I know that I can add expires header using mod_expires. However, what can I do if the Apache server doesn't have mod_expires installed and I don't want to route the access to the files through a scripting language like PHP?
Asked
Active
Viewed 7,782 times
3 Answers
7
You could use mod_header to set the header field manually:
Header set Expires "..."
But since Expires requires an absolute time, use Cache-Control’s max-age parameter for times relative to the access time:
Header merge Cache-Control max-age=3600

Gumbo
- 643,351
- 109
- 780
- 844
-
So you mean instead of using Expires header, use Cache-Control header? – Sebi Sep 02 '10 at 10:24
-
Works, only using Cache-Control and not Expires. – Sebi Sep 02 '10 at 11:40
2
If you have static Expires headers, the following will add an Expires header to your js and css files:
<FilesMatch "\.(js|css)$">
Header set Expires "Fri, 01 Jan 2010 00:00:00 GMT"
</FilesMatch>

Suman
- 9,221
- 5
- 49
- 62

Lekensteyn
- 64,486
- 22
- 159
- 192
-
1The problem is I need to calculate the future date based on the current access time and I can't use a fixed date. So this won't work. – Sebi Sep 02 '10 at 10:23
1
This should tell the browser to refresh the page on subsequent visits. The expires date just has to be in the past... you could set the date using PHP to make it "just" in the past, or just leave it as the date you found this answer!!!
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Thu, 2 Sep 2010 05:00:00 GMT");
UPDATE: Apologies - I missed the "Don't" in the sentence about routing files through PHP! You can also use these HTML meta tags:
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="expires" content="Thu, 2 Sep 2010 05:00:00 GMT">

Fenton
- 241,084
- 71
- 387
- 401
-
Sorry, this won't work, because I need to add Expires header to non-html files. But ok, I forgot to write that in my initial question. – Sebi Sep 02 '10 at 10:25