【问题标题】:Access-Control-Allow-Origin FilesMatch not working for types other than EOTAccess-Control-Allow-Origin FilesMatch 不适用于 EOT 以外的类型
【发布时间】:2015-10-28 19:05:42
【问题描述】:

我正在为我的网站提供来自无 cookie 域的资源。由于 Chrome 和 Firefox 中的跨站点原因,这已被阻止

Redirect at origin 'http://static.domain.com' has been blocked from loading by Cross-Origin Resource Sharing policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://www.domain.com' is therefore not allowed access.

所以我在 htaccess 文件中添加了以下内容以启用 CORS

<IfModule mod_setenvif.c>
  <IfModule mod_headers.c>
    # mod_headers, y u no match by Content-Type?!
    <FilesMatch "\.(gif|png|jpe?g|svg|svgz|ico|webp)$">
      SetEnvIf Origin ":" IS_CORS
      Header set Access-Control-Allow-Origin "*" env=IS_CORS
    </FilesMatch>
  </IfModule>
</IfModule>

<IfModule mod_headers.c>
  <FilesMatch "\.(ttf|ttc|otf|eot|woff|woff2|font.css|css|js|svg)$”>
    Header set Access-Control-Allow-Origin “*”
  </FilesMatch>
</IfModule>

由于某种原因,这不能正常工作 - eot 文件返回正确的标题,但 ttf、woff 和 svg 不会。我有点困惑为什么!我是不是语法有误?

EOT 标头

Access-Control-Allow-Origin *
Date    Sun, 25 Oct 2015 19:41:30 GMT
Last-Modified   Sat, 24 Oct 2015 10:22:45 GMT
Server  cloudflare-nginx
CF-RAY  23b066397718352a-LHR
Content-Type    application/vnd.ms-fontobject

TTF 标头

Date    Sun, 25 Oct 2015 21:57:58 GMT
Last-Modified   Sat, 24 Oct 2015 10:22:44 GMT
Server  cloudflare-nginx
Content-Type    application/x-font-ttf
Cache-Control   max-age=31104000
Accept-Ranges   bytes
CF-RAY  23b12e202e1735ea-LHR
Content-Length  199248
Expires Wed, 19 Oct 2016 21:57:56 GMT

【问题讨论】:

    标签: regex .htaccess http-headers cross-domain


    【解决方案1】:

    我注意到 ttf 被缓存而 eot 没有。当您使用 cloudfare 时,它​​很可能遵循了这些缓存指令,因此正在提供缓存版本。

    请参阅此处了解更多信息以及可能的解决方法:https://support.cloudflare.com/hc/en-us/articles/203063414-Why-can-t-I-see-my-CORS-headers-

    【讨论】:

    • 我也有同样的想法,但是在清除 cloudflare 缓存并将其切换到开发模式后,问题仍然存在。
    • 您能否从您的原始 Web 服务器(可能使用 IP 地址)确认 Web 服务器配置是否有问题或 cloudflare? Web 服务器配置对我来说看起来不错,但最好确认一下。
    猜你喜欢
    • 2013-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-17
    • 2015-09-17
    • 2014-06-15
    • 2013-09-09
    相关资源
    最近更新 更多