Vue 路由器到子文件夹 - 刷新时生产中出现 404

问题描述 投票:0回答:1

我正在使用 vite.config.js 中的“base: '/my-app/'”在子域的生产环境中提供我的 vue.js 应用程序(这里没有问题)

有问题的 URL 示例:my-domain/my-app/my-component

通过路由器链接访问有问题的 URL 时没有问题,但刷新该页面时,我收到 404 错误。(在网络选项卡中出现错误后,我得到“strict-origin-when-cross-origin”)

根据我的理解,我应该使用 .htaccess 将所有 URL 重定向到“index.html”,如 here 所解释的那样,但是一旦我这样做了,我的控制台中就会收到一个意外的标记,因为我的文档类型从

<!DOCTYPE html\>
替换为
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 

*我在子文件夹中使用 .htaccess 文件,以防产生任何影响

提前谢谢您

vue.js redirect http-status-code-404 refresh subdirectory
1个回答
0
投票

.htaccess 代码将所有内容重定向回index.html,以防在某些时候对其他人有所帮助:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/vue-chat/index.html$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !\.(css|gif|ico|jpg|js|png|swf|txt|svg|woff|ttf|eot)$
RewriteRule . index.html [L]
© www.soinside.com 2019 - 2024. All rights reserved.