question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Manage 404 page in Next app deployment

See original GitHub issue

Hi,

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:closed
  • Created 3 years ago
  • Comments:16

github_iconTop GitHub Comments

10reactions
fanismahmalatcommented, Sep 8, 2021

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.

5reactions
bobbyhadzcommented, Dec 9, 2020

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: redirects

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found