CORS policy: No ‘Access-Control-Allow-Origin’ [Solution]

The Access-Control-Allow-Origin header specifies whether the resources of the specified origin can be used or not.

    Inhaltsangabe
  1. The problem
  2. The solution

I had a problem with my old website some time ago and wrote a blog post about it. Now I have transferred this post to my new blog. It’s about the following error message:

Access to Font at ‘https://www.konzeptcode.com/wp-content/themes/konzeptcode-theme/fonts/fontawesome/fontawesome-webfont.woff2?v=4.3.0’ from origin ‘https: // reta. concept code ‘has been blocked by CORS policy: No’ Access-Control-Allow-Origin ‘header is present on the requested resource. Origin ‘https: //reta.conceptcode’ is therefore not allowed access.

The problem

I tried to load a resource from the origin of a domain, even though I’m currently in a subdomain. I’ve tried to access https://konzeptcode.com from https://ht.konzeptcode.com . This must be allowed separately.

The solution

You have different ways around this problem. If you only temporarily load the resources from there and use Google Chrome, I recommend you to install a plugin.

However, if you are always going to load resources from another subdomain, you can bypass this error message by making a change to the htaccess file.

Header set Access-Control-Allow-Origin "*"
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
Header set Access-Control-Allow-Origin "*"
RewriteCond %{HTTP_HOST} ^konzeptcode.com$ [NC]
RewriteRule (.*) https://www.konzeptcode.com/$1 [R=301,L]
# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.php)$ $1 [L]
RewriteRule . index.php [L]

Topics

Apache Experience Program technology Tips website WordPress

Beitrag teilen

WhatsApp it

Folgen Sie uns