Here's a new take on a common problem.
So I have a plesk hosting, with a SSL on wildcard domains.
I have a wordpress theme which is using Font-Awesome icons, hosted on the same server.
I have added the following lines to my /httpdocs/.htaccess file, at the very top:
<IfModule mod_headers.c>
<FilesMatch ".(ttf|ttc|otf|eot|woff|woff2|font.css|css)$">
Header set Access-Control-Allow-Origin "*"
</FilesMatch>
</IfModule>
I use the polylang translation plugin, which is set to use subdomain for different language:
- mysite.com (English)
- fr.mysite.com (French)
When I access example.com, everything works fine.
When I access fr.example.com, I get a lot of the following errors in the console:
Access to font at 'https://example.com/wp-content/plugins/elementor/assets/lib/font-awesome/webfonts/fa-brands-400.woff2' from origin 'https://fr.example.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
I was expecting the error to go away by adding the Header set lines to my .htaccess but it does not seem to help at all. According to Plesk I do have the Headers module activated.
I do use NGINX as a proxy to Apache, all with default configs. I did try to add the following lines, just in case, but all 3 attempts lead to Error 500:
#NGINX < 1.4
if ($filename ~* ^.*?.(eot)|(ttf)|(woff)$){
add_header Access-Control-Allow-Origin *;
}
# NGINX 1.4
location ~* .(eot|ttf|woff|woff2)$ {
add_header Access-Control-Allow-Origin *;
}
# NGINX > 1.6
if ($request_uri ~* ^.*?.(eot)|(ttf)|(woff)$) {
add_header Access-Control-Allow-Origin *;
}
I also tried to add this in the .htaccess without success:
Header set Access-Control-Allow-Origin "*"
It almost seem as the .htaccess is not being loaded, but then the rewrite rules and the caching headers from WP-Optimize works fine and are from the same file.
Any idea what I am doing wrong ?
question from:
https://stackoverflow.com/questions/65865883/font-awesome-has-been-blocked-by-cors-policy-no-access-control-allow-origin-h 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…