我以前用过这个;
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/gif "now plus 2 weeks"
// Lots omitted here
</IfModule>
还有这个;
<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>
我可以通过内容类型设置过期时间,并可以通过文件扩展名设置任何标头。
但是这两者似乎都无法让您根据内容类型设置所需的任何标头。
我想根据响应的内容类型设置缓存控制标头 - 请注意,这与文件扩展名不同。 我有“友好的URL”,因此没有要由filesMatch
捕获的文件扩展名,但内容类型为text/html
。
如何针对特定的内容类型设置缓存控制标头?
ExpiresByType
指令所做的事情(确切地说,它设置了Cache-Control
头的max-age
指令以及向后兼容性的Expires
头)。但是,如果您想要在Cache-Control
头中设置“任何头”或特定指令,则需要使用不同的方法。 - MrWhite