Overwrite cache headers with mod_expires

I want to set cache headers using the mod_expires module from apache. My configuration looks something like this:

<LocationMatch ^/static > ExpiresDefault "access plus 1 years" </LocationMatch> 

The problem is that the files are generated by a third system that I do not control. This system provides files with the following headers:

 Date Mon, 24 Oct 2011 08:39:02 GMT Cache-Control no-cache,no-store,must-revalidate Pragma no-cache Expires Thu, 01 Dec 1994 16:00:00 GMT 

These headers do not allow you to set cache headers using mod_expires. http://httpd.apache.org/docs/2.2/mod/mod_expires.html tells us why:

When the Expires header is already part of the response generated by the server, for example, when a CGI script is generated or proxied from the source server, this module does not change or does not add the Expires or Cache-Control header.

Is there any possible way around this rule and overwrite headers with mod_expires?

Update: One possible solution to avoid this limitation is to use only mod_headers to set cache headers. Unfortunately, this is not an alternative, because the values ​​must be calculated.

Thanks for this.

+8
apache mod-expires
source share
3 answers

Unfortunately, this is a known limitation, and we had to refuse only to use mod_headers .

+4
source share

Have you tried mixing it with mod_headers ?

 <LocationMatch ^/static > Header unset Cache-Control Header unset Pragma Header unset Expires ExpiresDefault "access plus 1 years" </LocationMatch> 

Not verified, but in case ...

0
source share

Regilero's suggestion will not work because the header directives will be processed very late in processing the response - after mod_expire . That way, you turned off the headers after mod_expires did (or didn't) what it was supposed to do.

If this is apache 2.2, you can try placing early at the end of each header directive. This will tell you to do this at an early stage in processing the response, not at the end.

try:

 <LocationMatch ^/static > Header unset Cache-Control early Header unset Pragma early Header unset Expires early ExpiresDefault "access plus 1 years" </LocationMatch> 

Did not test tho, but try ...

0
source share

All Articles