【问题标题】:Wordpress cross domain issuesWordpress 跨域问题
【发布时间】:2015-01-03 14:21:18
【问题描述】:

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

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

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

有没有办法在 Wordpress 中改变这一点?不仅必须用于样式表,还可以用于 Wordpress 引用的所有文件。

【问题讨论】:

    标签: wordpress cross-domain


    【解决方案1】:

    您可以通过在您的 .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

    【讨论】:

      猜你喜欢
      • 2017-08-29
      • 2017-08-15
      • 2012-03-12
      • 2012-12-11
      • 2011-07-05
      相关资源
      最近更新 更多