【问题标题】:404 error when IE loads fontsIE 加载字体时出现 404 错误
【发布时间】:2017-08-31 09:40:30
【问题描述】:

我这样称呼我的字体:

@font-face {
  font-family: 'dinar';
  src: url('../fonts/dinarm.eot?#'),
       local('?'),
       local('Mj_Dinar Two Medium'),
       url('../fonts/dinarm.woff') format('woff'),
       url('../fonts/dinarm.ttf') format('truetype'),
       url('../fonts/dinarm.svg') format('svg');
  font-weight: normal;
  font-style: normal
}
@font-face {
  font-family: 'font-bmi';
  src: url('../fonts/font-bmi/font-bmi.eot');
  src: url('../fonts/font-bmi/font-bmi.eot') format('eot'),
       url('../fonts/font-bmi/font-bmi.woff') format('woff'),
       url('../fonts/font-bmi/font-bmi.ttf') format('truetype');
  font-weight: normal;
  font-style: normal
}

每次使用 Internet Explorer 的用户尝试访问该站点时,我都会在网络主机使用日志中看到大量 404 错误,最后该用户被我的安全插件禁止。有一个使用日志的例子:

80.00.000.146 - - [05/Apr/2017:00:46:10 +0430] 
"GET /wp-content/themes/fonts/font-bmi/font-bmi.eot)%20format(%22eot%22),
%20url(../fonts/font-bmi/font-bmi.woff)%20format(%22woff%22),
%20url(../fonts/font-bmi/font-bmi.ttf)%20format(%22truetype%22 HTTP/1.1" 404 4058 
"http://www.21tech.ir/some-page/" "Mozilla/4.0 
(compatible; MSIE 8.0; Windows NT 5.1; --some other information--)"

我知道它写了Mozilla/4.0,但它实际上是 IE 我已经测试过了。

有什么问题,如何解决或避免?

【问题讨论】:

  • 路径应该相对于 css 文件本身,而不是来自调用 css 的页面。这是正确的道路吗?
  • @iguypouf 是的,它只发生在 IE 上。

标签: css internet-explorer http-status-code-404 font-face


【解决方案1】:

原因是旧版本的 IE 无法正确解释第二个 @font-face 声明中的第二个 src 属性。称为Fontspring @font-face syntax 的解决方案是在该属性中的 .eot URL 的末尾附加一个问号 (?),诱使 IE 认为后面的所有内容都是查询字符串:

@font-face {
    font-family:"font-bmi";
    src:url("../fonts/font-bmi/font-bmi.eot?#iefix") format("embedded-opentype"),
        url("../fonts/font-bmi/font-bmi.woff2") format("woff2"),
        url("../fonts/font-bmi/font-bmi.woff") format("woff"),
        url("../fonts/font-bmi/font-bmi.ttf") format("truetype");
    font-weight:normal;
    font-style:normal
}

您已经尝试了一些不同的“hacks”来解决您的第一个@font-face 声明中的问题,但是,尽管您已经成功地阻止了 IE 报告 404,但上述解决方案更加简洁并且不会影响CSS 的可读性。

如需进一步阅读,请参阅 Paul Irish 在 2009 年发表的“Bulletproof @font-face syntax”文章。

【讨论】:

  • 其实我的每个字体都看到了错误,第一个不行,我只是粘贴了部分错误。我尝试了您的建议,但没有成功。
  • 您的答案中的第一个链接,完成了这项工作。谢谢。
  • 您必须做出哪些改变?它与我的解决方案有何不同?
  • 使用这个:@font-face{font-family:'font-bmi';src:url('../fonts/font-bmi/font-bmi.eot');src: url('../fonts/font-bmi/font-bmi.eot?#iefix') format('embedded-opentype'),url('../fonts/font-bmi/font-bmi.woff') format('woff'),url('../fonts/font-bmi/font-bmi.ttf') format('truetype');font-weight: normal;font-style: normal}
  • 嗯...你不应该需要第一个src属性,你可以尝试删除它,看看它是否仍然有效?
猜你喜欢
  • 2012-02-23
  • 2015-05-17
  • 2013-10-12
  • 1970-01-01
  • 2013-11-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-16
相关资源
最近更新 更多