【问题标题】:mod_expires not setting cache-control headers on JPEG imagesmod_expires 未在 JPEG 图像上设置缓存控制标头
【发布时间】:2011-07-06 05:53:36
【问题描述】:

我不明白为什么我正在处理的网站中的普通旧 JPEG 图像(大约十几个,< 10 KB 每个)不会采用它们被强制馈送的缓存控制标头。我使用的.htaccess 规则基于最新的HTML5 Boilerplate .htaccess file(下面的相关部分)。奇怪的是,网站中的 PNG 数量大致相同,而且除了其中两个之外,缓存控制标头都可以正常工作。

<IfModule mod_expires.c>
  ExpiresActive on

# Perhaps better to whitelist expires rules? Perhaps.
  ExpiresDefault                          "access plus 1 month"

...

# media: images, video, audio
  ExpiresByType image/gif                 "access plus 1 month"
  ExpiresByType image/png                 "access plus 1 month"
  ExpiresByType image/jpg                 "access plus 1 month"
  ExpiresByType image/jpeg                "access plus 1 month"

...

  <IfModule mod_headers.c>
    Header append Cache-Control "public"
  </IfModule>

</IfModule>

(省略号表示删除了多余的ExpiresByType 规则部分)

我已经从我的/etc/apache2/apache2.conf 文件一直到其中包含的几乎所有 conf 文件,但找不到任何合理的解释。我也摆弄过,Pagesped 和 Chrome 审计了好几个小时,我仍然一无所知。

编辑:如下所述,该网站的网络根目录中只有一个.htaccess 文件。 JPEG 以 mime 类型 image/jpeg 很好,但缓存控制标头丢失了,我不知道为什么。

【问题讨论】:

    标签: apache .htaccess apache2 http-headers mod-expires


    【解决方案1】:

    我将no-transform 添加到mod_headers 部分,果然,一切正常。现在我可以让墙从我的额头上休息一下了。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-28
      • 2020-02-08
      • 2021-01-01
      • 2011-10-01
      • 2020-09-24
      • 2019-03-13
      • 1970-01-01
      • 2018-06-19
      相关资源
      最近更新 更多