Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Font from subdomain has been blocked by Cross-Origin Resource Sharing Policy

I'm having the following error Font from origin 'http://static.example.com' 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://www.example.com' is therefore not allowed access.

I am using the following COR setting in .htaccess file here below

<IfModule mod_expires.c>
  ExpiresActive on
  ExpiresDefault "access plus 1 month"
  ExpiresByType text/cache-manifest "access plus 0 seconds"

  ........

  <IfModule mod_headers.c>
     Header append Cache-Control "public"
     <FilesMatch "\.(ttf|otf|eot|woff|svg)$">
       SetEnvIf Origin "^http://(.*)?example.com$" origin_is=$0
       Header set Access-Control-Allow-Origin %{origin_is}e env=origin_is
     </FilesMatch>
     <FilesMatch "\.(js|css|xml|gz)$">
       Header append Vary: Accept-Encoding
     </FilesMatch>
  </IfModule>
</IfModule>

Please I need help with this

like image 374
amachree tamunoemi Avatar asked Jun 19 '16 20:06

amachree tamunoemi


People also ask

Does CORS apply to subdomains?

Yes you have to enable it. You have to send CORS allow headers from server side to your browser. This is because a subdomain counts as a different origin. You probably have to allow HTTP methods like PUT, DELETE, OPTIONS as well.

What is cross origin resource sharing in aws?

Cross-origin resource sharing (CORS) defines a way for client web applications that are loaded in one domain to interact with resources in a different domain. With CORS support, you can build rich client-side web applications with Amazon S3 and selectively allow cross-origin access to your Amazon S3 resources.

What is a CORS issue?

The CORS behavior, commonly termed as CORS error, is a mechanism to restrict users from accessing shared resources. This is not an error but a security measure to secure users or the website which you are accessing from a potential security bleach.


3 Answers

Try this in your .htaccess file:

# Allow font assets to be used across domains and subdomains
<FilesMatch "\.(ttf|otf|eot|woff|woff2)$">
  <IfModule mod_headers.c>
     Header set Access-Control-Allow-Origin "*"
  </IfModule>
</FilesMatch>

You can read more about this issue in this excellent article I found: https://expressionengine.com/learn/cross-origin-resource-sharing-cors

like image 183
bg17aw Avatar answered Oct 19 '22 02:10

bg17aw


You can also try this

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

More at https://davidwalsh.name/cdn-fonts

like image 36
Airy Avatar answered Oct 19 '22 04:10

Airy


Try adding this to your .htaccess file:

Header add Access-Control-Allow-Origin "http://example.com"

Alternative:

Header add Access-Control-Allow-Origin "*"
like image 2
Joe Avatar answered Oct 19 '22 04:10

Joe