我使用Apache 2.2与mod_proxy到一些第三方HTTP服务器。
由于它不发送任何Cache-Control
头,我想为响应代码200添加1天中的一个,为404添加5分钟,为任何其他响应代码添加0。
所以我会喜欢:
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
我知道我的答案可能来得太晚,但是对于任何想要根据条件在HTTP响应中设置标题的人来说都是有用的,特别是对于HTTP状态码的条件。
你可以在这里find这样一个configuration的例子(例#8):
- 追加一个caching标题为HTTP状态代码200:
Header append Cache-Control s-maxage=600 "expr=%{REQUEST_STATUS} == 200"
它可以扩展为支持基于请求/响应环境variables的任何条件。
这个例子适用于Apache httpd v2.4:我怀疑它不适用于httpd v2.2 …