On Tuesday 25 October 2011, Noah Robin wrote:
> I ran some tests on this and the following modified version will
> work:
>
> Header always set Cache-Control max-age=%{CACHE_LIFETIME}e
> env=CACHE_LIFETIME
> RewriteRule /example http://www.example.com/
> [E=CACHE_LIFETIME:604800]
>
> ..however, this still leaves an open question in my mind: How to
> solve for the more general case where I want Apache to set the
> cache control header on any 301 it sends, even if the 301 was
> generated within the application rather than in Apache's
> configuration. I don't see a way to set an environment variable
> based on a response attribute (e.g. r->status). Am I missing
> something or would something need to be written to handle this
> case?
2.3/2.4 supports this:
Header set Cache-Control max-age=604800 "%{REQUEST_STATUS} == 301"
or even "%{REQUEST_STATUS} -in { 301 , 302 }". This is a good
candidate for an example in the docs.
I can't think of a way to do this in 2.2.x, though.