Apache httpd:根据其他 *response* 标头有条件地设置响应标头 [英] Apache httpd: Conditionally set response header based on other *response* header

查看:38
本文介绍了Apache httpd:根据其他 *response* 标头有条件地设置响应标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法有条件地设置新的响应标头,条件使用另一个响应标头?具体来说,只有当响应具有特定的 Content-Type 时才应该设置新的响应头.

Is there a way to set a new response header conditionally, where the condition uses another response header? Specifically, the new response header should be set only if the response has a certain Content-Type.

我研究了 mod_headersmod_setenvif 但看起来条件只能使用 request 标头,不是响应头.

I have looked into mod_headers in combination with mod_setenvif but it looks like conditions can only use request headers, not response headers.

谢谢,约翰

推荐答案

Apache 2.4 就是答案:

Apache 2.4 is the answer:

当响应内容类型为 application/pdf 时设置 Cache-Control 标头

Set Cache-Control header when response content type is application/pdf

Header set Cache-Control "no-store,no-transform" "expr=%{resp:Content-Type} =~ m|application/pdf|"

不要尝试使用 IF 指令.它在过程中过早评估.例如,以下将不起作用:

Do NOT try with the IF directive. It is evaluated too early in the process. For example, the following will NOT work:

标头集缓存控制无存储,无转换"</If>

这篇关于Apache httpd:根据其他 *response* 标头有条件地设置响应标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆