Alexandre D
Alexandre D

Reputation: 3

CORS policy unsolvable with .htaccess

I have a website www.1.com which access to font on a subdomain sub.1.com When I load the page, I have the famous "blocked by CORS policy, no access-control-allow-origin."

So, I add in the root of my subdomain a .htaccess with :

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

I tried with mod_header.c and other. But none work !

What did I wrong ? Thank you for your help, I know there is a lot of question regarding CORS, but I really do not understand what I'm doing wrong...

Upvotes: 0

Views: 85

Answers (1)

kenef
kenef

Reputation: 183

Looks like you need to replace 'set' with 'add' and remove 'always'.

Header add Access-Control-Allow-Origin "*"
Header add Access-Control-Allow-Methods: "GET,POST,OPTIONS,DELETE,PUT"

You could also set the headers in wordpress functions.php file like so

function add_cors_http_header(){
    header("Access-Control-Allow-Origin: *");
}
add_action('init','add_cors_http_header');

Both of these should get you taken care of.

Upvotes: 1

Related Questions