问题
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
回答1:
I found the issue: I didn't set the base_url in the config.php from CodeIgniter. After setting it everything works.
回答2:
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:
Just put the following, it should work.
<CORSConfiguration>
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET<enter code here/AllowedMethod>
</CORSRule>
</CORSConfiguration>
回答4:
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/";
来源:https://stackoverflow.com/questions/34998629/cross-origin-resource-sharing-policy-blocking-glyphicons-from-bootstrap-in-codei