【发布时间】:2017-08-23 01:51:45
【问题描述】:
我有一个使用 Amazon S3 和 Cloudflare 启动并运行的 Vue.js 应用程序。
当我打开索引并浏览到 /dashboard 时,一切正常。但是,当我直接在新选项卡中打开仪表板之类的路线或刷新页面时,我从 S3 收到以下错误:
404 Not Found
Code: NoSuchKey
Message: The specified key does not exist.
Key: unternehmen
RequestId: 6514F8A1F4C29235
HostId: +BVrPLJSGdzSYogzWZ4GMBXkgkdSJWRVJVhcSs4EI/lmMUR422aCtCxpBGU6AMe5VkS1UbEn/Lc=
刚刚看到问题出在 Vue.js 历史模式:https://router.vuejs.org/de/essentials/history-mode.html
我想通过我的 Amazon S3 存储桶中的路由规则来解决问题。 Apache RewriteRule 如何查找 S3?
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
尝试了以下方法,但它不起作用:
<RoutingRules>
<RoutingRule>
<Condition>
<HttpErrorCodeReturnedEquals>404</HttpErrorCodeReturnedEquals>
</Condition>
<Redirect>
<HostName>domain.com</HostName>
<ReplaceKeyWith>index.html</ReplaceKeyWith>
</Redirect>
</RoutingRule>
</RoutingRules>
如果我这样做,我只会渲染我的页眉和页脚,但仅此而已。
谢谢!
【问题讨论】:
-
所以...你关闭了历史模式?
-
是的,没有让它在 S3 和历史模式下工作。
-
@mrks 接受的答案 [S3 重定向] 是否适用于您的哈希模式?
-
当您将 S3 存储桶设置为静态网站存储桶时,您有 2 个字段:索引文档和错误文档。你需要做的就是为 index 和 error 填充相同的值——“index.html”和 vue router 将处理其余的
标签: amazon-s3 vue.js vue-router s3-rewrite-rules