Codeigniter CORS策略:无"Access-Control-Allow-Origin"错误如何解决? [英] Codeigniter CORS policy: No 'Access-Control-Allow-Origin' error How to resolve?

查看:160
本文介绍了Codeigniter CORS策略:无"Access-Control-Allow-Origin"错误如何解决?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

错误: 在" http://www.example.com//assets/global/plugins/font-awesome/fonts/fontawesome-webfont.woff2?v=4.4.0 '源自来源" http://example.com ".

Error: Access to Font at 'http://www.example.com//assets/global/plugins/font-awesome/fonts/fontawesome-webfont.woff2?v=4.4.0' from origin 'http://example.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://example.com' is therefore not allowed access.

解决方案:

<?php
header('Access-Control-Allow-Origin: *');

class Home extends CI_Controller {
    public function index()
    {
        $this->load->view('master');
    }
}
?>

我尝试了此解决方案,但是它不起作用,您能帮我解决该问题吗?以及如何从URL中删除index.php?

I tried this Solution but it not working can you please help me How to resolve it? and How to remove index.php from URL?

推荐答案

尝试允许GET&选项

Try allowing GET & OPTIONS

<?php
header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Methods: GET, OPTIONS");

如果上述方法不起作用,请尝试允许通过.htaccess(对于Apache)或在Nginx服务器块中访问字体资源-添加以下行:

If the above doesn't work, try allowing access to font resources via .htaccess (for apache) or in nginx server block - add these lines:

# Apache config
<FilesMatch ".(eot|ttf|otf|woff)">
    Header set Access-Control-Allow-Origin "*"
</FilesMatch>

# nginx config
if ($filename ~* ^.*?\.(eot)|(ttf)|(woff)$){
    add_header Access-Control-Allow-Origin *;
}

这篇关于Codeigniter CORS策略:无"Access-Control-Allow-Origin"错误如何解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆