.htaccess - How to set expires to date in past?

4.9k views Asked by At

I noticed that Google sets the expiration of its HTML to a date in the past:

Expires Thu Jan 01 1970 00:00:00

How do I configure .htaccess to do this? I use ExpiresByType to set the expiration of my other resources, but they are all future times (e.g. access plus 10 years). Any suggestions on how to set it for the past? Thanks.

1

There are 1 answers

4
Michael Irigoyen On BEST ANSWER

By setting the expiration of the HTML to the past, I'm assuming you're trying to prevent your HTML from being cached. Unfortunately, you cannot use the Expires directive as it only works for future dates. You can use header commands though to control how your HTML files are cached.

<FilesMatch "\.(html|htm)$">
FileETag None
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Thu, 01 Jan 1970 00:00:00 GMT"
</FilesMatch>

The mod_headers module will need to be installed in Apache to use this method.

EDIT: Alternatively, if you're using PHP, you can set these headers using PHP's header function.

header("Cache-Control: max-age=0, no-cache, no-store, must-revalidate");
header("Pragma: no-cache");
header("Expires: Thu, 01 Jan 1970 00:00:00 GMT");