wordpress - "Access to Font..has been blocked by CORS policy"只有一个文件

标签 wordpress amazon-web-services amazon-s3 cdn amazon-cloudfront

Note: I am using Wordpress and serving the media files, css, js, etc. through Amazon CloudFront/S3.



你好,
我知道有很多这样的帖子,但我仍然在挣扎。我能够为我正在加载的大多数字体文件解决这个问题,但是,这个问题仍然存在。
Access to Font at 'http://mycloudfrontID.cloudfront.net/wp-content/themes/bridge/css/font-awesome/fonts/fontawesome-webfont.woff2?v=4.6.3' from origin 'http://mydomainname' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://maxmajor.net' is therefore not allowed access.

将其添加到 AWS S3 上的 CORS 策略后,其他字体文件就可以了:
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
    <AllowedOrigin>*</AllowedOrigin>
    <AllowedMethod>GET</AllowedMethod>
    <MaxAgeSeconds>3000</MaxAgeSeconds>
    <AllowedHeader>Authorization</AllowedHeader>
</CORSRule>
</CORSConfiguration>

这是在我的 .htaccess 中:
<FilesMatch "\.(ttf|ttc|otf|eot|woff|woff2|font.css)$">
<IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin "*"
</IfModule>
</FilesMatch>

任何想法为什么这个错误仍然被触发?

谢谢,
布赖恩

最佳答案

尝试改变:

Header set Access-Control-Allow-Origin "*" 

有了这个:
Header add Access-Control-Allow-Origin "*"

我也读过
How does Access-Control-Allow-Origin header work?

Font from origin has been blocked from loading by Cross-Origin Resource Sharing policy

出于安全原因,您必须包含您的 URL。

所以,你的 .htaccess 应该有这个:
<FilesMatch "\.(ttf|ttc|otf|eot|woff|woff2|font.css)$">
<IfModule mod_headers.c>
    Header add Access-Control-Allow-Origin "http://mysitename.com"
</IfModule>
</FilesMatch>

为我工作!

关于wordpress - "Access to Font..has been blocked by CORS policy"只有一个文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44574315/

相关文章:

javascript - 从基于 WordPress 构建的 ReactJS 应用程序发出 POST 请求

javascript - 用户注册表单不显示-用户提交表单插件-wordpress

amazon-web-services - AWS Eventbridge : Pattern to capture ALL events

asp.net - 图像无法上传到 Amazon S3 服务器

php - 如何在 WordPress/WooCommerce 3+ 中将自定义字段添加到评论表单

php - 当 woocommerce 产品中没有内容时隐藏自定义选项卡

amazon-web-services - cloudformation更新堆栈不是幂等的

node.js - Ubuntu EC2 端口开放问题

c# - 使用 IIS .Net ASP.Net 中的 AWS S3 API 时,对象引用未设置为对象的实例

powershell - 写入Amazon AWS S3时排除文件或某些类型