Redirecting all 404's to index

Using _redirect rules, how can you redirect all 404’s to the index page?

I don’t have a 404.html page, but I’d like to just simply redirect all the 404 to the main index page.

I’ve read the docs on https://docs.netlify.com/routing/redirects/redirect-options/#http-status-codes to no success. I tried to use /* /index 404 but it only shows the index page without changing the URL.

So if I were to go on mysite.com/nonexistentpage with the _redirect rule above in place, it will just go to mysite.com/nonexistentpage but it will show the contents of the index page. I would like it to make it go to mysite.com/ instead.

If it is a SPA you can use this: https://docs.netlify.com/routing/redirects/rewrites-proxies/#history-pushstate-and-single-page-apps

It is not SPA, there is other pages too.

The documentation for the 404 status says this:

With this status code, the page content will change, but the URL in the browser address bar will not.

If you want to change the URL, would you try using a 301 redirect instead? If that doesn’t work, please let us know.

How can I catch all the 404’s with a 301/302 redirect?

I’d like to redirect the URL of any 404 requests, for example, mysite.com/nonexistentpage, which results in 404, to the root index. I don’t know how to check if it’s a 404 though.

You might try @jonian’s suggestion. Even though you’re not building a single page app, that redirect rule (200 without !) will redirect requests to any non-existent page at your URL back to index.html. Because shadowing! See more here: Changed behavior in redirects

With this feature, we check if a file exists for a given path before applying a redirect rule. If a file exists, we will serve that file rather than applying the rule, unless the rule is forced, because forced rules always take effect.

Let us know if that works for you!