I have a Next.js app with three routes: /home, /about, and /contact.
If a user lands on a route that doesn't exist, by default, Next.js will direct them to the 404 page.
However, I want to avoid redirecting them to the 404 page. Instead, I'd like to establish a permanent redirection to /home. This means that if someone lands on an unavailable route, they will automatically be redirected to /home.
I need to set this up from the server side in the Next.js config file. The reason for this is that I recently acquired a domain, and users are currently hitting a lot of 404 pages for URLs that used to be live. I want to minimize the number of users encountering 404 errors.
While it's relatively straightforward to implement this when we know the specific unknown page a user might land on, without knowing the exact routes, we'll likely need to use a regex pattern. Unfortunately, I'm struggling to figure out how to do this.
Could you please provide guidance on potential solutions or approaches to achieve this?