【发布时间】: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