2016-06-19 69 views
7

我是从原产地“http://static.example.com”具有以下错误字体已经加载的跨来源资源共享政策阻止:无“访问控制 - 允许 - Origin'标题出现在请求的资源上。因此不允许访问原产地'http://www.example.com'。字体已被封锁的跨来源资源共享政策

我使用下文

<IfModule mod_expires.c> 
    ExpiresActive on 
    ExpiresDefault "access plus 1 month" 
    ExpiresByType text/cache-manifest "access plus 0 seconds" 

    ........ 

    <IfModule mod_headers.c> 
    Header append Cache-Control "public" 
    <FilesMatch "\.(ttf|otf|eot|woff|svg)$"> 
     SetEnvIf Origin "^http://(.*)?example.com$" origin_is=$0 
     Header set Access-Control-Allow-Origin %{origin_is}e env=origin_is 
    </FilesMatch> 
    <FilesMatch "\.(js|css|xml|gz)$"> 
     Header append Vary: Accept-Encoding 
    </FilesMatch> 
    </IfModule> 
</IfModule> 

请我需要这个

回答

1

尝试增加这.htaccess文件帮助.htaccess中COR设置:

Header add Access-Control-Allow-Origin "http://example.com" 

替代方案:

Header add Access-Control-Allow-Origin "*" 
+0

我试过,但它不工作,谢谢。 –

+0

试试我已经添加到答案的替代选项。 – Lag

7

试试这个在您的.htaccess文件:

# Allow font assets to be used across domains and subdomains 
<FilesMatch "\.(ttf|otf|eot|woff|woff2)$"> 
    <IfModule mod_headers.c> 
    Header set Access-Control-Allow-Origin "*" 
    </IfModule> 
</FilesMatch> 

您可以将这个优秀的文章,我发现在阅读更多关于这个问题:https://expressionengine.com/learn/cross-origin-resource-sharing-cors

+0

非常好。非常感谢你 –

相关问题