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

查看:127
本文介绍了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_headers "http://httpd.apache.org/docs/2.2/mod/mod_setenvif.html" rel ="noreferrer"> mod_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 "%{resp:Content-Type} =~ m|application/pdf|"> Header set Cache-Control "no-store, no-transform" </If>

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

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

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