按Content-Type设置标题

Jak*_*e N 7 apache content-type header apache2

我之前用过这个;

<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType image/gif "now plus 2 weeks"
  // Lots omitted here
</IfModule>
Run Code Online (Sandbox Code Playgroud)

还有这个;

<IfModule mod_headers.c>
  <filesMatch "\\.(ico|pdf|flv|jpg|jpeg|png|gif|swf|JPG)$">
    Header set Cache-Control "max-age=1209600"
  </filesMatch>
  // Lots omitted here
</IfModule>
Run Code Online (Sandbox Code Playgroud)

我可以按内容类型设置过期,我可以通过文件扩展名设置任何标题.

但这些似乎都不允许你按内容类型设置任何你想要的标题.

我想根据响应的内容类型设置缓存控制头 - 请注意,这与文件扩展名不同.我有"友好的URL",所以没有文件扩展名被捕获,filesMatch因此没有文件扩展名,但内容类型是text/html.

如何为特定内容类型设置缓存控制标头?

cov*_*ner 7

在2.4中,您可以将expr =附加到Header指令而不是env =.

在默认(非早期)模式下,mod_headers作为输出过滤器运行 - 因此内容类型已经设置并且可由表达式解析器使用

http://httpd.apache.org/docs/2.4/expr.html