Home
Support Forums

Redirect to an index page if specific page does not exist

Hi,

We have a lot of event registration pages on our site. These pages are taken down a wee while after the event has happened. In case anyone hits a link to a page that’s gone, I want a redirect rule that - if the page doesn’t exist (ie. don’t force it), takes them instead to our events index page. However, it’s not working.

If feel like:
/events/* /events/ 301

should work - and it says it is valid - but if I then try and go to a page at events/… that doesn’t exist, I get a 404.

If I update it, to randomly redirect people to our blog page, like this:

/events/* /blog/ 301

it works as expected - but I don’t want to do that. Has anyone got a redirect rule like this working, where you’re saying anything within a section should redirect to the index page if it doesn’t exist?

Hi @katcoutts,

Could you provide your site address that’s having this issue?

Generally this happens when you’re about to run into an infinite redirect loop. So, Netlify sends a 404 instead of a 301 to break the loop and prevent the browser from displaying Too Many Redirects page.

In the redirect rule that you’ve shown above, the case I explained just now could occur when you don’t have any events.html or events/index.html page - maybe you’re relying on some kind of server side rendering for that?

This was just a general explanation of the most probable cause - but I could provide deeper insights with the actual site name to test and inspect.

1 Like