我有以下错误 Font from origin ' http://static.example.com ' 已被跨源资源共享策略阻止加载:请求的资源上不存在“Access-Control-Allow-Origin” header 。起源' http://www.example.com ' 因此不允许访问。
我在下面的 .htaccess 文件中使用以下 COR 设置
<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>
请我需要帮助
最佳答案
在您的 .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
关于wordpress - 来自子域的字体已被跨域资源共享策略阻止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37911448/