Manage 404 page in Next app deployment
See original GitHub issueHi,
I am following these instructions to deploy a Next app with the CLI.
Everything works great.
However, I have a question regarding 404 page. I have set up a custom 404 page which is correctly exported by Next in the /out
folder. This 404 is showing well in dev
mode when I try to access a wrong URL.
After deploying my app with amplify publish
, I try to access a wrong URL and I’m getting a 403 AccessDenied
. It seems logical since the deployment is only static.
So my question is: is there any way to be redirected to /404 when accessing a wrong URL?
Thanks for your help.
Which Category is your question related to?
Hosting
Amplify CLI Version
4.37.1
Issue Analytics
- State:
- Created 3 years ago
- Comments:16
Top Results From Across the Web
Making a custom 404 page in Next.js - Netlify
The 404 error is special because it is always statically generated, but the others rely on the server. If you'd like to use...
Read more >404 Page not found Vercel Deployment - using dynamic ...
It works as expected in localhost but in Vercel deployment, even before the functions are executed, I get a 404 error. Note: Vercel...
Read more >Custom 404 Page – Vercel Docs
Zero Configuration Deployments. In most cases, creating and deploying a custom 404 page for your application will work without any additional configuration.
Read more >Getting 404 for resources for the deployed Nextjs application
I'm using Nx workspace with the following directory structure: apps courses nextjs next-config.js dist apps courses nextjs .next.
Read more >Error pages in the JSS Next.js sample app
If you want to handle specific status codes and render the built-in error page on routes, you can import the Error component from...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
If anyone is asking, I found a solution that works for me. Basically you need to remove the rule for redirecting to 404 completely in Rewrites and redirects. Next.js will handle the ‘not found’ itself.
You can add a custom redirect for folders and paths that can’t be found and map it to your
/404.html
page.In your AWS Amplify console - click on the app and then click Rewrites and redirects. Add the
/<*>
source address to map to/404.html
target address (your next.js custom page), with the type of 404 (Rewrite).The rewrites and redirects for my site look like:
As you mentioned, it’s not really next.js specific it’s just a static site, but it should maybe be added in the docs, since you would have to add this redirect in 100% of the cases when deploying a Next.js static site.