In the header response, I want to remove Cache-Control's "max-age"? I don't want to completely unset Cache-Control, though -- just want to get rid of max-age. So the following would be wrong:

Header unset Cache-Control

I think there is a way to do this using "edit" instead of "unset". However, I'm not sure how to use "edit".



You can do something like:

Header edit Cache-Control ^(.*)max-age=(\d+)(.*)$ \1\3

This should remove the 'max-age= from the Cache-Control header.

|improve this answer|||||
  • Marco, I want to get rid of max-age, not keep it. I assume that is Perl regex. Would this be correct: ^(.*)(max-age=\d+,? )(.*)$/$1$3/ig – StackOverflowNewbie Jul 31 '11 at 13:14
  • It's a regular expression, yes, and I was wrong in that I put the wrong backreference; it's not Perl, however; take a look at mod_headers documentation, there is a little sample there. Fixed in the answer. – Marco Bizzarri Jul 31 '11 at 13:23
  • Marco, this is from httpd.apache.org/docs/current/glossary.html#regex: "Apache uses Perl Compatible Regular Expressions provided by the PCRE library." What is your reference that says it is not Perl? – StackOverflowNewbie Jul 31 '11 at 20:36
  • As far as I can tell, ^(.*)(max-age=\d+,? )(.*)$/$1$3/ig is not a regular expression, it is the perl syntax to make a search & replace using the regular expression ^(.*)(max-age=\d+,? )(.*)$. If you look at the syntax of the Header directive in the mod_headers, you can see that it states: "For edit there is both a value argument which is a regular expression, and an additional replacement string." httpd.apache.org/docs/current/mod/mod_headers.html#header – Marco Bizzarri Jul 31 '11 at 21:47

Set it with different value:

Header set Cache-Control "private, no-cache, no-store, ..."

It will replace the previous header.

|improve this answer|||||
  • Setting it to a different value is not an option. There are too many resources with too many different Cache-Controls. Basically, the only thing they have in common is that I want to remove max-age. – StackOverflowNewbie Jul 31 '11 at 11:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.