【问题标题】:Favicon Content-Type: text/plain - "AddType image/ico .ico" doesn't workFavicon Content-Type: text/plain - “AddType image/ico .ico”不起作用
【发布时间】:2011-11-24 16:36:18
【问题描述】:

我要求我的开发人员通过在 .htaccess 文件中添加以下行来设置网站图标的过期日期:

<IfModule mod_expires.c>
ExpiresByType image/ico "access plus 1 years"

但它没有过期日期,直到我在 Firefox 中加载图标并注意到响应标头的这一部分后才弄清楚

Content-Type: text/plain; charset=WINDOWS-1251

然后我被建议添加以下内容:(让 Apache 为网站图标设置正确的 mime 类型)

<IfModule mod_mime.c>
AddType image/ico .ico
</IfModule>

但它没有成功,不知道为什么,会不会有任何冲突覆盖 mod_mime.c?或任何其他原因?

请指教

谢谢

补充:我目前有这个设置过期日期:

<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/gif "access plus 1 years"
ExpiresByType image/jpeg "access plus 1 years"
ExpiresByType image/png "access plus 1 years"
ExpiresByType image/x-icon "access plus 1 years"
ExpiresByType text/css "access plus 1 years"
ExpiresByType text/javascript "access plus 1 years"
ExpiresByType application/x-javascript "access plus 1 years"
ExpiresByType application/x-shockwave-flash "access plus 1 years"
</IfModule>

【问题讨论】:

  • 您是否在 .htaccess 文件中在 ExpiresByType 之前设置了 ExpiresActive On
  • 过期不是问题,因为它适用于所有文件类型,但图标除外
  • 是否安装了mod_mime?在任何情况下,您都可能需要考虑更激进的到期。雅虎使用 10 年,这是 Steve Sauders 推荐的。

标签: apache .htaccess optimization http-headers


【解决方案1】:

您也可以尝试将以下内容添加到您的 .htaccess 文件中。

<IfModule mod_header.c>

  <FilesMatch "\.ico$">
    # cache .ico files for 1 year(31536000 sec)
    Header set Cache-control max-age=31536000
  </FilesMatch>

</IfModule>

编辑:

注意,你有

AddType image/ico .ico

你正在使用的bur

ExpiresByType image/x-icon "access plus 1 years"

这也可能是问题所在。要解决,您可以更改为

AddType image/x-icon .ico

【讨论】:

  • 首先感谢:) @Ulrich 看到我在上面添加的内容,我需要更改任何内容还是只添加您的几行?输入行的顺序有什么不同吗?
  • 在你的之后添加我的行,即在结束 mod_expires.c &lt;/IfModule&gt;
  • AddType image/x-icon .ico 没有帮助,还没有尝试其他解决方案,这里有趣的是,当我在 .htaccess 中添加 时子文件夹它确实有效(虽然不想在子文件夹上使用 htaccess,但宁愿尝试找出问题的原因)
猜你喜欢
  • 2011-04-02
  • 1970-01-01
  • 1970-01-01
  • 2012-05-19
  • 2016-01-23
  • 2019-09-13
  • 1970-01-01
  • 2019-05-01
  • 2014-09-17
相关资源
最近更新 更多