When accessing page from link/refreshing etc. it redirects to 404 page

My problem is that I have a serverless netlify page build with next-on-netlify. I’ve added redirection to my custom 404 page, and that works fine. The problem occurs when accessing the page from a link or when refreshing the page. In these cases it gives me the 404 page instead of the actual content on given url.

I’ve already tried to add:

  1. Move _redirects file to public and add /* index.html 200 (This didn’t add the redirects at all in build file)

  2. Move _redirects file to root and add /* index.html 200

  3. add /* index.html 200 infront of my 404 redirect in root (It displayed the default 404 page on all pages).

Heya! Have you checked out this handy guide? It’ll talk you through making sure your redirects are read and the rule needed for SPAs… and then some!

Read the article, and it doesn’t seem to have a solution for my exact problem

Hey there! There’s only so much I can do when the site’s behind a login screen :frowning_face:!

Any chance you can create a reproduction without the login, providing some steps to show the error?

Knowing that this is next-on-netlify related, you may wish to check a discussion such as this out.

Not sure that issue is related to mine… I will provide you with login details in a private message.
To produce the problem:

  1. Enter dashboard
  2. Refresh page/access it from link

Hey @MohammadSaad1,

When I refresh https://base-web.netlify.app/dashboard, I’m not getting a 404. Are you locally caching at all? I’m not able to reproduce!

If you are still having this issue, can you provide an x-nf-request-id for a 404?

I’ve removed redirections on the published version. To reproduce try this one:

That deploy doesn’t have the /* /index.html 200 rule that a SPA requires.

I have already tried it with /* /index.html 200

An example of that is this build: https://app.netlify.com/sites/base-web/deploys/5f7dd229d1c8490008001576

That example has the 404 rule above the 200 rule. Flip them around so the 200 rule comes first; order is important. :slight_smile:

Tried that as well;

Looking at other next-on-netlify examples, _redirects:

  • Start with function-driven redirects
  • Ends with static redirects (such as 404)

Which makes sense because the catch-all 404 will take precedence over other remaps when it’s at the top of the file!

Not quiet sure what to do from here, since these rules are auto-generated except the redirects. :smiley:

Not sure what this means :confused: But, you can always manipulate your redirects after the build command (you can create a script which tweaks your redirects to however you need them formatting, depending on what works!)