_redirects rule for all 404 page to homepage

I create a _redirects file in Gridsome root folder /static like this -

/* / 301

but its not working…

I’m confused. That redirect rule looks like it would cause an infinite loop.

1 Like

i want to redirect all 404 pages into homepage

Sorry, should have read the title better, but I’m pretty sure that isn’t possible because Pages doesn’t know the response code or what is missing when determining to redirect.

2 Likes

anyone please help…

ErrorDocument 404 /blog
/* /blog 301

i tried like this but not working

_redirects doesn’t know response codes to do it conditionally.

Create a 404.html page that uses a meta refresh tag to the home page.

2 Likes

i hear meta refresh tag is bad for seo… thats why I want to use 301

what is the goal here exactly? If you don’t have a 404.html then every request will already route towards your index.html
See Serving Pages · Cloudflare Pages docs

If this isn’t your goal can you explain it? I’m really not sure what the objective is here.

1 Like

You won’t be able to do this using _redirects. You could do it with Functions middleware, by awaiting next(), checking the response, and if 404 then redirect, but you’d need to run a Function on every route. This is the approach I would take with a 404.html committed (to avoid SPA serving and get Pages to serve 404s) if I were to implement this.

I’d be wary of doing this though… 404s aren’t necessarily a bad thing, and redirecting every 404 to your homepage almost certainly isn’t great for SEO. If example.com/something doesn’t exist and redirects back to my homepage, you’re going to struggle with Google not knowing what the canonical of a page is if you’re not careful. Not to mention if you do then add a page at that URL, you’re going to cause further issues for yourself.

2 Likes

i have 404.html.

I bought a expired domain which has so many sub-directory(domain.com/blog-post-999) backlink.

And I don’t want to lose backlink.

Redirecting all of those sub-pages to your homepage is a very quick way to get search engines to ignore them entirely and cause even more damage to your SEO.

If you don’t have specific pages that are relevant to those blog posts to redirect to, I would very much let them 404.

3 Likes

Thank you so much. :heart:

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.