7

I use Apache 2.2 with mod_proxy to some 3rd party HTTP server.

As it doesn't send any Cache-Control header, I want to add one of 1 day for response code 200, 5 min for 404 and 0 for any other response code.

So I would something like :

SetEnvIf HttpResponseCode "200" rc_200
SetEnvIf HttpResponseCode "404" rc_404

Header set "Cache-Control" "private, max-age=0"
Header set "Cache-Control" "public, max-age=86400" env=rc_404
Header set "Cache-Control" "public, max-age=86400" env=rc_200

1 Answer 1

3

I know that my answer is probably coming too late, but it can be useful to anyone wanting to set a Header in a HTTP Response based upon a condition, and more specifically upon a condition on the HTTP Status code.

You can find here an example of such a configuration (example #8) :

  1. Append a Caching header for responses with a HTTP status code of 200 :
    Header append Cache-Control s-maxage=600 "expr=%{REQUEST_STATUS} == 200"

It can be extended to support any condition based upon Request/Response environment variables.

This example works for Apache httpd v2.4 : I suspect that it doesn't work for httpd v2.2...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .