为什么@ font-face在woff文件上抛出404错误?

我在公司的网站上使用了@font-face ,它看起来很棒。 除了Firefox和Chrome会在.woff文件上引发404错误。 IE不会抛出错误。 我有位于根目录的字体,但我已经试过在CSS文件夹中的字体,甚至给整个url的字体。 如果从我的CSS文件中删除这些字体,我不会得到一个404,所以我知道这不是一个语法错误。

另外,我使用了fontsquirrels工具来创build@font-face字体和代码:

 @font-face { font-family: 'LaurenCBrownRegular'; src: url('/laurencb-webfont.eot'); src: local('☺'), url('/laurencb-webfont.woff') format('woff'), url('/laurencb-webfont.ttf') format('truetype'), url('/laurencb-webfont.svg#webfontaaFhOfws') format('svg'); font-weight: normal; font-style: normal; } @font-face { font-family: 'FontinSansRegular'; src: url('/fontin_sans_r_45b-webfont.eot'); src: local('☺'), url('/fontin_sans_r_45b-webfont.woff') format('woff'), url('/fontin_sans_r_45b-webfont.ttf') format('truetype'), url('/fontin_sans_r_45b-webfont.svg#webfontKJHTwWCi') format('svg'); font-weight: normal; font-style: normal; } 

我遇到了同样的症状 – 在Chrome浏览器中的woff文件上404,并且在带有IIS 6的Windows Server上运行应用程序。

如果您处于相同的情况,则可以通过执行以下操作来解决问题:

解决scheme1

“只需通过IISpipe理器(网站属性的HTTP标题选项卡)添加以下MIMEtypes声明: .woff application / x-woff

更新:根据woff字体和Grsmto的MIMEtypes,实际的MIMEtypes是application / x-font-woff (至less适用于Chrome)。 x-woff将修复Chrome 404s,x-font-woff将修复Chrome的警告。

IIS 6 MIME类型

感谢Seb Duggan: http : //sebduggan.com/posts/serving-web-fonts-from-iis

解决scheme2

您也可以在Webconfiguration中添加MIMEtypes:

  <system.webServer> <staticContent> <remove fileExtension=".woff" /> <!-- In case IIS already has this mime type --> <mimeMap fileExtension=".woff" mimeType="application/x-font-woff" /> </staticContent> </system.webServer> 

实际上@I罗宾逊的答案效果很好,但Chrome将继续抱怨这样的消息:“ 资源解释为字体,但与MIMEtypes的应用程序/ x-woff传输

如果你明白了,你可以改变

应用程序/ x-WOFF

application / x -font -woff

而且您不会再有任何Chrome控制台错误!

(在Chrome 17上testing)

这个post的答案是非常有用的,节省了大量的时间。 不过,我发现在使用FontAwesome 4.50 ,我不得不为woff2types的扩展添加一个额外的configuration,如下所示,否则woff2types的请求在Chrome的开发工具中给出了一个404错误,在Console> Errors下。

根据S.Serp的评论,下面的configuration应该放在<system.webServer>标签中。

 <staticContent> <remove fileExtension=".woff" /> <!-- In case IIS already has this mime type --> <mimeMap fileExtension=".woff" mimeType="application/x-font-woff" /> <remove fileExtension=".woff2" /> <!-- In case IIS already has this mime type --> <mimeMap fileExtension=".woff2" mimeType="application/x-font-woff2" /> </staticContent> 

IIS7解决scheme

我也遇到了同样的问题。 我认为从服务器级别进行configuration会更好,因为它适用于所有的网站。

  1. 转到IIS 根节点,然后双击“MIME Types”configuration选项

  2. 点击右上angular的动作面板中的“添加”链接。

  3. 这会带来一个对话框。 添加.woff文件扩展名,并指定“application / x-font-woff”作为相应的MIMEtypes。

添加.woff文件扩展名的MIMEtypes

转到MIME类型

添加MIME类型

这是我做了什么来解决IIS 7中的问题

运行IIS服务器pipe理器(运行命令:inetmgr)打开MIMEtypes并添加以下内容

文件扩展名: .woff

MIMEtypes :application / octet-stream

除了伊恩的回答,我不得不允许请求过滤模块中的字体扩展使其工作。

 <system.webServer> <staticContent> <remove fileExtension=".woff" /> <remove fileExtension=".woff2" /> <mimeMap fileExtension=".woff" mimeType="application/x-font-woff" /> <mimeMap fileExtension=".woff2" mimeType="application/x-font-woff" /> </staticContent> <security> <requestFiltering> <fileExtensions> <add fileExtension=".woff" allowed="true" /> <add fileExtension=".ttf" allowed="true" /> <add fileExtension=".woff2" allowed="true" /> </fileExtensions> </requestFiltering> </security> </system.webServer> 

解决了它:

我不得不使用Mo'Bulletproofer方法

这可能是显而易见的,但它已经绊了我404s多次…确保字体文件夹权限设置正确。

另外检查你的URL重写器。 如果发现“怪异”,可能会抛出404。

我尝试了许多权限,MIMEtypes等等,但是对于我来说,它最终是因为web.config已经删除了IIS中的静态文件处理程序,然后明确地将它添加回来,以获取具有静态文件的目录。 只要我为我的目录添加一个位置节点,并添加了处理程序,请求停止获取404s。

如果你没有访问你的web服务器configuration,你也可以重新命名字体文件,以svg结尾(但保留格式)。 在Chrome和Firefox中为我工作正常。

如果您在IIS7下使用CodeIgniter:

在你的web.config文件中,添加woff模式

<rule name="Rewrite CI Index"> <match url=".*" /> <conditions> <add input="{REQUEST_FILENAME}" pattern="css|js|jpg|jpeg|png|gif|ico|htm|html|woff" negate="true" /> </conditions> <action type="Rewrite" url="index.php/{R:0}" /> </rule>

希望能帮助到你 !

如果在添加MIMEtypes后仍不能正常工作,请检查网站身份validation部分是否启用了“匿名身份validation”,并确保按照给定的屏幕截图select“应用程序池身份”。

在这里输入图像说明

IIS Mimetypes:.woff字体/ x-woff(不是应用程序/ x-woff或应用程序/ x-font-woff)