Overwrite cache-headers with mod_expires
Asked Answered
C

3

10

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

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

The problem is, that the files are generated by a third system I don't control. These 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 makes it impossible to set the cache-headers with 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 generated by a CGI script or proxied from an origin server, this module does not change or add an Expires or Cache-Control header.

Is there any possible way to circumvent this rule and overwrite the headers with mod_expires?

Update: One possible solution, to avoid this limitation is to use only mod_headers to set the cache-headers. Unfortunately, this isn't an alternative because the values have to be calculated.

Thanks it advance.

Casares answered 28/10, 2011 at 13:50 Comment(0)
C
4

Unfortunately, it's a known limitation and we had to fall back to use only mod_headers.

Casares answered 19/11, 2012 at 10:15 Comment(0)
A
1

Regilero's suggestion won't work because header directives will be processed very late in the response processing - after mod_expire directive. So you'd unset the headers after mod_expires did (or didn't) what it was supposed to do.

If it's apache 2.2 you could try putting early at the end of each header directive. That will tell it to do this in an early stage of response processing as opposed to at the end.

so try:

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

Haven't tested tho, but give it a try...

Artemisia answered 18/11, 2011 at 17:6 Comment(0)
H
0

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 tested, but in case of...

Hildebrandt answered 29/10, 2011 at 20:1 Comment(5)
Mh, this didn't work. It only removes the headers. ExpiresDefault has no effect.Casares
scheffield: ok, that's half of the steps :-) Maybe you could still use the Header module instructions to push the new headers and not the Expires module. If you only need this default setting and no ExpiresByType it could maybe work.Hildebrandt
this isn't an alternative for use because the access clause has to be calculated.Casares
@Casares Did you ever get this fixed?Recidivate
Nopp, its a known limitation and we had to fall back to use only mod_headers.Casares

© 2022 - 2024 — McMap. All rights reserved.