简体   繁体   中英

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?

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.

SetEnvIf will not work for this purpose because it only matches Request Headers.

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.

2) Configure Apache to set the Cache-Control header only if it's still set to empty string.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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