Cross-Origin Resource Sharing policy blocking glyp

2020-06-30 05:01发布

I'm trying to use the glyphicons provided by Bootstrap 3.3.6 but Chrome is blocking the access to them with this error message:

Font from origin 'http://[::1]' has been blocked from loading by Cross-Origin Resource Sharing policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.

This is my .htaccess:

   <IfModule authz_core_module>
      Require all denied
   </IfModule>
   <IfModule !authz_core_module>
      Deny from all
   </IfModule>
   <FilesMatch "\.(ttf|otf|eot|woff)$">
      <IfModule mod_headers.c>
        Header set Access-Control-Allow-Origin "*"
      </IfModule>
   </FilesMatch>

What am I doing wrong? Am I editing the wrong .htaccess?

I also tried adding header("Access-Control-Allow-Origin: *"); at the beginning of my header.php file but that didn't work either. I'm out of ideas.

The folder structure is like this:

   application
       controller
       model
       view
           header.php
           index.php
           footer.php
       .htaccess
   system
   assets
       css
       fonts
       images
       js

4条回答
beautiful°
2楼-- · 2020-06-30 05:41

You need to add the base URL to your configuration file:

$config['base_url'] ='http://www.urlname.com';

We can set this way so we can move any server no need to change try this one.

$config['base_url'] = 'http://'.$_SERVER['HTTP_HOST'].'/';
查看更多
乱世女痞
3楼-- · 2020-06-30 05:51

Just put the following, it should work.

<CORSConfiguration>
    <CORSRule>
        <AllowedOrigin>*</AllowedOrigin>
        <AllowedMethod>GET<enter code here/AllowedMethod>
    </CORSRule>
</CORSConfiguration>
查看更多
Rolldiameter
4楼-- · 2020-06-30 05:57

Allowing cross-site scripting may cause security issues, try to adjust your codeigniter options;

1.) Go to application/config/config.php file, 2.) find $config['base_url'] = ""; and 3.) place your project folder's path as value. $config['base_url']="http://localhost/yourProjectFolder/";

查看更多
▲ chillily
5楼-- · 2020-06-30 06:00

I found the issue: I didn't set the base_url in the config.php from CodeIgniter. After setting it everything works.

查看更多
登录 后发表回答