环境:
Windows 10
phpstudy8.1-[Apache2.4.39]
问题:
使用内网穿透后,网站的woff字体无法访问,报错跨域问题,导致字体无法加载,网站效果不理想
报错文字:
Access to Font at 'http://******.cn/content/templates/emlog_dux/fonts/fontawesome-webfont.woff?v=4.2.0' from origin 'http://blog.fishwood.cn' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://******.cn' is therefore not allowed access.
(也有可能是内网穿透改域名未及时更新问题导致,此方法备用)
解决方法:
在Apache配置文件中,添加代码:
<IfModule mod_headers.c>
<FilesMatch "\.(svg|ttf|otf|eot|woff|woff2)$">
Header set Access-Control-Allow-Origin "*"
</FilesMatch>
</IfModule>
参考:https://www.uedbox.com/post/50992/