Question about redirects for fallback 404 page

Dear Netlify Team,

I’m trying to set up the custom fallback 404 page, but doesn’t work.

site: https://spontaneous-puppy-ed9a21.netlify.app/

Redirects settings as follows, the multilingual 404 pages work fine, but the fallback 404 page doesn’t work. Am I doing something wrong?

# multilingual 404 pages.
[[redirects]]
  from = "/:lang/*"
  to = "/:lang/404.html"
  status = 404

# fallback 404 page.
[[redirects]]
  from = "/*"
  to = "/en/404.html"
  status = 404

What do you mean by “doesn’t work”? (Displays a different 404 page, redirect loop, 5xx error …)?

It probably would also help the Netlify folks to mention you are using Hugo (at least I think I recognize you from the Hugo forums and presume that is the SSG which you are using).

1 Like

Hi, I expect that the following 404 pages work.

  • /en/invalid-pageen/404.html
  • /zh-hans/invalid-pagezh-hans/404.html
  • /invalid-pageen/404.html

But the last one doesn’t use the fallback 404 page (en/404.html) defined in redirects.

I could copy the en/404.html to 404.html, but it would be nice that I’m able to define it in redirects without copying files.

What does it end up using?

It uses Netlify built-in 404. e.g.
https://spontaneous-puppy-ed9a21.netlify.app/invalid-page/.

Perhaps have a look at this suggestion

1 Like

Thanks, I already set it up (work as expected for multilingual 404), but the fallback 404 page seems not working.

https://spontaneous-puppy-ed9a21.netlify.app/invalid-page/ - not working, which I wish to fallback to use en/404.html.

https://spontaneous-puppy-ed9a21.netlify.app/en/invalid-page/ - works.

https://spontaneous-puppy-ed9a21.netlify.app/zh-hans/invalid-page/ - works.

While probably not the answer you’re looking for. the simplest thing is to duplicate the /en/404.html page to /404.html which Netlify would automatically serve for any invalid page.

Yep, it’s a workaround, but it would be nice without copying files.

The problem here is that you’re using placeholders. For example, taking your above redirects config:

And matching that with: https://spontaneous-puppy-ed9a21.netlify.app/invalid-page/

invalid-page now acts as the :lang placeholder. So based on your rule, Netlify tries to look for /invalid-page/404.html, and that doesn’t exist. Thus, the default 404. The solution is to explicitly define all languages instead of relying on placeholders.

2 Likes

Thanks for explanation.