【问题标题】:403 error for loading font file CodeIgniter加载字体文件 CodeIgniter 时出现 403 错误
【发布时间】:2013-11-12 17:06:24
【问题描述】:

您好,我是 Codeigniter 的新手。我正在通过 css 为我的网站使用外部字体文件。这是我的css代码:

@font-face {
font-family: 'ElegantIcons';
src:url('http://localhost/findacare/font/ElegantIcons.eot'),
    url('http://localhost/findacare/font/ElegantIcons.eot?#iefix') format('embedded-opentype'),
    url('http://localhost/findacare/font/ElegantIcons.woff') format('woff'),
    url('http://localhost/findacare/font/ElegantIcons.svg#ElegantIcons') format('svg'),
    url('http://localhost/findacare/font/ElegantIcons.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}

但我在加载文件时收到以下错误文件

GET http://localhost/findacare/font/ElegantIcons.woff 404 (Not Found) manage_profile:1
GET http://localhost/findacare/font/ElegantIcons.svg 404 (Not Found) /findacare/font/ElegantIcons.svg#ElegantIcons:1
GET http://localhost/findacare/font/ElegantIcons.ttf 404 (Not Found) /findacare/font/ElegantIcons.ttf:1

我的文件结构是:

findacare-
          -application
          -css
          -font
          -images

即使给出绝对路径,我也检查了很多次。谁能帮帮我。

【问题讨论】:

  • 你的文件结构是fonts; 404 消息正在查看 font
  • 抱歉我的文件结构是字体。我打错了
  • 请发布您的.htacces。您的 htaccess 中可能有一个文件夹白名单,而您尚未指定字体文件夹。测试这一点的一种方法是将字体文件夹移动到 css 文件夹中并相应地更新链接。如果它开始工作,则说明您的字体文件夹尚未被列入白名单。
  • 您的 webroot 中有一个 .htaccess 文件(与您的 index.php 相同的目录)。我向您保证它就在那里,因为没有它您的应用程序将无法运行。 . dot 格式的文件在某些​​操作系统上是隐藏的,因此您可能需要先显示隐藏文件才能打开它。
  • 我已经将字体文件夹添加到重写条件中,现在我可以直接访问字体文件夹了..非常感谢您的帮助..我的问题已经解决了。

标签: php css codeigniter fonts


【解决方案1】:

如果您查看 .htaccess 文件,您很可能有一行代码如下所示:

RewriteCond $1 !^(index\.php|robots\.txt|css/|js/|images/)

这是不会通过您的应用程序 index.php 传递的文件夹/文件的白名单。所有其他 url 将被传递到应用程序中。

因为你的字体文件夹在webroot,所以你需要把这个文件夹加入白名单,这样你的css规则才能访问到。

RewriteCond $1 !^(index\.php|robots\.txt|css/|js/|images/|font/)

【讨论】:

    【解决方案2】:

    我在我的一个项目中使用过这样的方法,如果您在 css 文件夹内的 css 文件中有这些行,那么试试这个可能会有所帮助:

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

    【讨论】:

    • 然后确保您的文件夹是可读的。直接在浏览器中点击此链接http://localhost/findacare/font/ElegantIcons.eot 即可查看。
    【解决方案3】:

    正如您在文件结构中提到的,文件夹名称是“fonts”,而在您的 css 源路径中,您使用的是“font”。

    【讨论】:

    • 感谢您的回复...对不起,我的文件夹结构只有“字体”..我输入错误..\
    猜你喜欢
    • 1970-01-01
    • 2018-10-24
    • 1970-01-01
    • 1970-01-01
    • 2017-08-31
    • 2013-10-12
    • 2020-03-10
    • 2016-03-07
    • 2012-06-04
    相关资源
    最近更新 更多