0

今天查看网站的源代码,发现有个glyphicons-halflings-regular.woff文件没有找到,因为我的网站使用了bootstrap的Glyphicons 字体图标,因此需要加载Glyphicons Halflings的相关文件,但是我的文件中明明有这个文件那怎么会报404错误呢?

glyphicons-halflings-regular.woff  404错误图片

那么具体是什么原因,我想到绝对路径中有,相同文件夹下的其他文件都可以找到为什么这个找不到呢?我发现这个文件的后缀是.woff,难道是因为我的服务器不支持这种文件,果然查资料知道我的空间使用的是Windows主机,因此需要修改一下配置,让IIS支持这种文件的访问,只需要修改网站根目录下的web.config添加如下代码即可

glyphicons-halflings-regular.woff  404错误解决方法的图片

还是把代码给大家好复制。

 <staticContent>
 	<remove fileExtension=".woff"/>
 	<mimeMap fileExtension=".woff" mimeType="application/font-woff" />
 </staticContent>

经过上面的修改就可以解决bootstrap中glyphicons-halflings-regular.woff字体报404错notfound的问题了。

转自:https://www.zhidao91.com/glyphicons-halflings-regular-woff-404-not-found/


这个是用bootstrap框架时我遇到的问题,个人解决过程如下:

① 这个资源不是我手动引用的,是bootstrap.min.css文件间接调用的。

② 默认的路径是css文件路径是project/css,引用的路径是project/fonts/*.ttf。

③ 添加fonts文件夹和文件,依然提示该错误,但是直接访问*.css文件就没问题。

④ 想起静态资源的调用是通过tomcat手动配置的。

⑤ 增加这些文件的匹配规则,在web.xml中增加如下配置:

复制代码
 1     <servlet-mapping>
 2         <servlet-name>default</servlet-name>
 3         <url-pattern>*.ttf</url-pattern>
 4     </servlet-mapping>
 5     <servlet-mapping>
 6         <servlet-name>default</servlet-name>
 7         <url-pattern>*.woff</url-pattern>
 8     </servlet-mapping>
 9     <servlet-mapping>
10         <servlet-name>default</servlet-name>
11         <url-pattern>*.woff2</url-pattern>
12     </servlet-mapping>
复制代码

⑥ OK,测试通过。

不想使用默认的文件路径怎么办?

⑦ 修改bootstrap.css关于ttf等资源调用的路径信息:

复制代码
 1 @font-face {
 2   font-family: 'Glyphicons Halflings';
 3 
 4   src: url('../fonts/glyphicons-halflings-regular.eot');
 5   src: url('../fonts/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'), 
 6   url('../fonts/glyphicons-halflings-regular.woff2') format('woff2'),
 7   url('../fonts/glyphicons-halflings-regular.woff') format('woff'),
 8   url('../fonts/glyphicons-halflings-regular.ttf') format('truetype'),
 9   url('../fonts/glyphicons-halflings       regular.svg#glyphicons_halflingsregular') format('svg');
10 }
复制代码

将fonts文件夹改成你实际的资源路径,然后引用bootstrap.css。

⑧ 这时发现bootstrap.css需要用到bootstrap.css.map文件。具体关系和原理尚需继续学习。


转自:https://www.cnblogs.com/yoyotl/p/5105683.html
关闭 返回顶部
联系我们
Copyright © 2011. 聚财吧. All rights reserved.