Wordpress themes files to another domain like CDN

ezramod

New member
Nov 9, 2020
16
2
3
Hi, is it possible to load static files (theme) on a domain and add them to LScache in CDN?

I try to do this but firs appear:
Access to font at 'https://seconddomain.com/wp-content/themes/v2/assets/fontawesome/webfonts/fa-brands-400.woff2' from origin 'https://domain_one.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.


after i add in .htaccess

<ifmodule mod_headers.c="">
SetEnvIf Origin "^(.*\.seconddomain\.com)$" ORIGIN_SUB_DOMAIN=$1
Header set Access-Control-Allow-Origin "%{ORIGIN_SUB_DOMAIN}e" env=ORIGIN_SUB_DOMAIN
Header set Access-Control-Allow-Methods: "*"
Header set Access-Control-Allow-Headers: "Origin, X-Requested-With, Content-Type, Accept, Authorization"
</ifmodule>

appear this:

(index):9 GET https://seconddomain.com/wp-content/themes/v2/assets/fontawesome/css/all.css net::ERR_ABORTED 404 - But if i access url files in browser works

second try was to add CNAME in domain one: cdn.domain_one.com to seconddomain.com and receive same error:

(index):9 GET https://cdn.domain_one.com/wp-content/themes/v2/assets/fontawesome/css/all.css net::ERR_ABORTED 404 - But if i access url files in browser works

have something ideea about this ?
 
Last edited:

simplysexyboy

Well-known member
Trusted Uploader
Oct 24, 2020
557
625
93
U.S.A
Hi

This is because web fonts are subject to Cross-Origin Resource Sharing (CORS). CORS is a way for a remote host to control access to certain types of resources.

To resolve this issue you need to ensure that your server is sending the correct Access-Control-Allow-Origin header when font files are requested. If you’re unable to modify your server configuration please contact your web host and tell them :

For Apache

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


for nginx

location ~* \.(eot|otf|ttf|woff|woff2)$ {
add_header Access-Control-Allow-Origin *;
}


also you may need to add “/*” to your CDN distribution.
 
  • Like
Reactions: nesym

About us

  • Our community has been around for many years and pride ourselves on offering unbiased, critical discussion among people of all different backgrounds. We are working every day to make sure our community is one of the best.

Quick Navigation

User Menu