【问题标题】:How to Enable Browser Caching on a per folder basis如何在每个文件夹的基础上启用浏览器缓存
【发布时间】:2014-12-27 00:06:40
【问题描述】:

浏览器缓存非常重要,所以我已经阅读并认为对我的网站执行此操作的最佳方法是指定每个文件夹的默认缓存持续时间,因为我知道我更新特定文件夹中文件的频率。但是,我当前的 htaccess 文件会导致 500 内部服务器错误...

# Turn off the Last Modified header except for html docs
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css)$">
Header unset Last-Modified

# Turn off the ETags
Header unset ETag
FileETag None
</FilesMatch>

## EXPIRES CACHING ##
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresDefault "access plus 1 minute"

  <Directory "/include">
    ExpiresDefault "access plus 1 week"
  </Directory>

  <Directory "/images">
    ExpiresDefault "access plus 1 year"
  </Directory>

  <Directory "/fonts">
    ExpiresDefault "access plus 1 year"
  </Directory>

  <Directory "/steamauth">
    ExpiresDefault "access plus 1 year"
  </Directory>

  ExpiresByType text/css "access plus 1 hour"
  ExpiresByType application/pdf "access plus 1 year"
  ExpiresByType application/x-shockwave-flash "access plus 1 month"
  ExpiresByType image/x-icon "access plus 1 year"

</IfModule>
## EXPIRES CACHING ##

我是在文件中弄乱了一些东西还是我这样做完全不正确?

【问题讨论】:

  • 您是否以文本模式发送了.htaccess 文件?
  • @Croises 不,因为我知道 .htaccess 文件有效,因为我使用它来设置自定义 404 错误页面。该代码有问题,因为一旦我删除它,我就不再收到 500 错误。
  • 检查 apache error_log 文件,它应该告诉你它不喜欢什么

标签: html apache .htaccess


【解决方案1】:

我知道它很旧,但我发现它正在寻找相同的答案。如果有人遇到类似问题,我这样做了:我为特定文件夹创建了一个新的 .htaccess 文件,并在其中修改了该文件夹的时间。非常适合我的情况。

【讨论】:

    猜你喜欢
    • 2020-03-28
    • 2020-07-19
    • 2012-12-25
    • 1970-01-01
    • 2012-04-21
    • 2016-04-05
    • 2016-12-31
    • 2011-05-29
    • 1970-01-01
    相关资源
    最近更新 更多