简体   繁体   English

Apache - 如果尚未添加,则添加Cache-Control标头

[英]Apache - Add Cache-Control header if not already added

In Apache, how can I set a Response Header only if it is not already set by the CGI application? 在Apache中,如果尚未由CGI应用程序设置响应标头,我该如何设置响应标头?

I need a way to automatically add the Cache-Control header to static content on my website, but I want the CGI application to be able to specify its own Cache-Control header too. 我需要一种方法来自动将Cache-Control标头添加到我网站上的静态内容,但我希望CGI应用程序能够指定自己的Cache-Control标头。

SetEnvIf will not work for this purpose because it only matches Request Headers. SetEnvIf不能用于此目的,因为它只匹配请求标头。

Is there some way to conditionally / optionally set a header if it is not already set? 如果尚未设置标题,是否有某种方法可以有条件地/可选地设置标题?

1) Configure Apache to append the value of empty string ( "" ) to the Cache-Control header to ensure the header is always included in the response. 1)配置Apache以将空字符串( "" )的值附加到Cache-Control标头,以确保标头始终包含在响应中。

2) Configure Apache to set the Cache-Control header only if it's still set to empty string. 2)配置Apache只有在设置为空字符串时才设置Cache-Control标头。

<FilesMatch "\.(css|ico|flv|gif|jpeg|jpg|js|pdf|png|swf)$">
  Header append Cache-Control ""
  Header edit Cache-Control "^[, ]*$" "max-age=1800, public"
</FilesMatch>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM