简体   繁体   English

AWS Amplify 将 Gatsby 404 重定向到根目录 URL

[英]AWS Amplify Redirects Gatsby 404 to Root URL

I have deployed a multi-page gatsby site both to AWS Amplify and Netlify.我已经为 AWS Amplify 和 Netlify 部署了一个多页 gatsby 站点。

When I go to a page that doesn't exist on my site that was deployed with Netlify, I get the 404 page I have created.当我将 go 转到使用 Netlify 部署的站点上不存在的页面时,我得到了我创建的 404 页面。 But when I go to the same non-existent route on the site with Amplify, it redirects me to the root path.但是,当我使用 Amplify 将 go 指向站点上相同的不存在路由时,它会将我重定向到根路径。

I have checked the network tab, and I get a 404 status code without any HTTP redirects.我检查了网络选项卡,我得到一个 404 状态代码,没有任何 HTTP 重定向。 So I assume the redirect happens in the JavaScript code?所以我假设重定向发生在 JavaScript 代码中?

Does this happen to anyone else?这在别人身上发生过吗?

Here is the default Rewrites and Redirects for my site on Amplify:这是我在 Amplify 上的网站的默认Rewrites and Redirects

在此处输入图像描述

The solution was to change the target address from /index.html to /404.html like this:解决方案是将目标地址从/index.html更改为/404.html ,如下所示:

在此处输入图像描述

I exprienced this same issue, but with all pages reloading to the homepage if they weren't ended with a '/'.我遇到了同样的问题,但是如果所有页面没有以“/”结尾,它们都会重新加载到主页。 Removing all the rewrite rules seemed to fix this for me.删除所有重写规则似乎为我解决了这个问题。 I wasn't using any of them and they were set as defaults.我没有使用它们中的任何一个,它们被设置为默认值。 Such as 'www' rerouting to '/'.比如'www'重路由到'/'。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM