【发布时间】:2022-06-16 20:31:16
【问题描述】:
我使用 REACT 和 Express 开发了一个系统。
它在本地运行良好。
当我部署到CPanel时,子路由器刷新时出现404错误,所以我添加了.htaccess这样。
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [QSA,L]
</IfModule>
添加后,我用 axios 调用后端 API 时出现 CORS 错误。
请帮帮我。
更新
如果我添加.htaccess,则会收到此错误。
Access to XMLHttpRequest at 'https://api.lightcoin.io/api/history?user=0x1C09d124d6c03EF63B1e0C3D1Af1b2eFE628ceE8' from origin 'https://lightcoin.io' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
如果我删除.htaccess,它可以正常工作,但是当刷新子路由器的页面时,我得到了404错误。
【问题讨论】:
-
请分享您遇到的 CORS 错误。
-
我已经更新了我的问题。
标签: reactjs .htaccess mod-rewrite server cpanel