2014-10-19 687 views
1

我遇到的问题与..Cross-Origin Resource Sharing policy: The 'Access-Control-Allow-Origin' header..WordPress的跨域问题

该网站上使用WPML插件3种不同的语言3个不同的域运行。对例如样式表URL指向1个URL(主域),这意味着其中2个站点正在请求信息跨域,并且这导致字体无法加载。

我希望通过从样式表的URL的protocal和域来解决这个问题,所以,它的指向一个“相对”路径文件(例如/wp-content/themes/salient/style.css?ver=4.8.1

有没有办法来改变这种在WordPress中?不仅仅适用于样式表,它可以适用于Wordpress引用的所有文件。

回答

2

可以允许通过添加下面一行到你的.htaccess文件从子域

加载资源从子域加载资源:从所有其他域

# Allow font, js and css to be loaded from subdomain 
SetEnvIf Origin "http(s)?://(.+\.)?(example\.com)$" ORIGIN_DOMAIN=$0 
<IfModule mod_headers.c> 
    <FilesMatch "\.(eot|font.css|otf|ttc|ttf|woff|js|png|jpg|jpeg|gif)$"> 
     Header set Access-Control-Allow-Origin %{ORIGIN_DOMAIN}e env=ORIGIN_DOMAIN 
    </FilesMatch> 
</IfModule> 

加载资源:

# Allow font, js, and css to be loaded from subdomain 
<IfModule mod_headers.c> 
    <FilesMatch "\.(eot|font.css|otf|ttc|ttf|woff|js|png|jpg|jpeg|gif)$"> 
     Header set Access-Control-Allow-Origin "*" 
    </FilesMatch> 
</IfModule> 

来源:http://www.webspeaks.in/2015/01/wordpress-allow-cross-domain-resources.html