Set a header by Content

I have used this before;

<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType image/gif "now plus 2 weeks"
  // Lots omitted here
</IfModule>

And this;

<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>

I can set the expires on by content-type and I can set any header I wish by file extension.

But neither of these seem to let you set any header you want by content-type.

I want to set the cache-control header based on the content-type of the response - note that this is not the same as the file extension. I have "friendly URLs" so there is no file extension to be captured by filesMatch so there is no file extension but the content-type is text/html .

How can I set the cache-control header for specific content-types?


In 2.4, you can append expr= to the Header directive instead of env=.

In the default (non-early) mode, mod_headers runs as an output filter -- so the content type is already set and available by the expression parser

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


I guess you will need to append or set the Cache-Control header first. Please try the snippet below and do not forget the "no-transform" param.

<IfModule mod_expires.c>
   ExpiresActive On
   ExpiresByType image/gif "now plus 2 weeks"
  // Lots omitted here

  //This is the magic
  <IfModule mod_headers.c>
     Header append Cache-Control "public, no-transform"
  </IfModule>

</IfModule>

如果你想创建缓存内容类型,你可以通过这种方式输入:

<IfModule mod_expires.c>

ExpiresActive on

ExpiresByType text/html "access plus 15 days"

</IfModule>
链接地址: http://www.djcxy.com/p/19004.html

上一篇: 每个设备有哪些iOS SDK指纹识别功能是唯一的?

下一篇: 按内容设置标题