如何为index.html设置缓存过期

时间:2013-10-10 19:28:12

标签: .htaccess

这是我在.htaccess文件中的一个部分,我从互联网上偷了一下并调整了一下

<ifModule mod_headers.c>
  Header set Connection keep-alive
  <filesMatch "\\.(ico|pdf|flv|jpg|jpeg|png|gif|swf)$">
    Header set Cache-Control "max-age=2592000, public"
  </filesMatch>
  <filesMatch "\\.(css)$">
    Header set Cache-Control "max-age=604800, public"
  </filesMatch>
  <filesMatch "\\.(js)$">
    Header set Cache-Control "max-age=604800, private"
  </filesMatch>
  <filesMatch "\\.(xml|txt)$">
    Header set Cache-Control "max-age=86400, public, must-revalidate"
  </filesMatch>
  <filesMatch "\\.(html|htm|php)$">
    Header set Cache-Control "max-age=86400, private, must-revalidate"
  </filesMatch>
</ifModule>

我在我的statik博客上使用它。我想以不同方式处理index.html文件,并将max-age设置为3600.但我不知道.htaccess文件究竟是如何工作的。

1 个答案:

答案 0 :(得分:1)

您可以在最后添加此代码段:

<filesMatch "index\.html$">
    Header set Cache-Control "max-age=3600, private, must-revalidate"
</filesMatch>