Redirecting to parent directory

I setup a _redirects file for where I am trying to redirect the following URLs:


/usa/2020/sponsors/ics /usa/2020/sponsors/ics-corporation 301

I am trying to redirect all other urls that do not match the most restrictive rules to the parent directory they are in. For example:

/webinars/xyz-123 → /webinars
/webinars/xyz-456 → /webinars

/usa/2020/speakers/abc-123 → /usa/2020/speakers/
/usa/2020/speakers/abc-456 → /usa/2020/speakers/

hi there, before we dig in, did you see this brand new guide on debugging redirects?

I strongly suggest you give it a thorough read through and see if this fixes your problem:

if not, please post again, and we’ll try and troubleshoot.

Hi, Yes I followed that documentation and all redirect rules are correctly firing except for this type of redirect. It looks like the problem is I have set them up with the most restrictive at the top and the least restrictive at the bottom. The problem is, as in my example, I can’t get the more general rule to execute. Is there a syntax problem? Essentially, I want to do what :splat: does except without the splat part.

Hey @digitaldavidg,

For these, you’ll need something like:

/webinars/* /webinars 301
/usa/2020/speakers/* /usa/2020/speakers/ 301

I hope this helps!

I have the following in my redirects file:

/webinars/lendit-investor-pitch-night /usa/2020/startups 301
/conferences/china-2016/videos / 302
/cookies /terms 301
/forum/innovation-in-p2p-lending-for-financial-advisors /webinars 301
/networking /usa/2020/networking 302
/press/media-coverage / 302
/press/media-partnerships / 302
/press/mentions / 302
/press/press-releases / 302
/press/signup / 302
/press/thanks / 302
/press/white-papers /white-papers 301
/team /about 302
/webinars/* /webinars 301
/careers/* / 302
/conferences/europe* /europe/2020 302
/conferences/usa* /usa/2020 302

Why doesn’t /webinars/blockchain 301 redirect to /webinars ?

Hey @digitaldavidg,

/webinars/blockchain 301 isn’t a valid redirect rule. You’d need something like /webinars/blockchain /webinars 301 or /webinars/* /webinars 301 :smile:

If /webinars/blockchain exists (a page/file is present) but you still want to redirect, you’ll need to use 301! in your rule (note the exclamation mark which forces the rule).

/webinars/blockchain is just an example. I want to redirect anything else in /webinars to the webinars directory without explicitly creating a rule for it. For example:

/webinars/lendit-investor-pitch-night /usa/2020/startups 301
/webinars/blockchain /webinars 301!
/webinars/apple /webinars 301!
/webinars/tree /webinars 301!
/webinars/frog /webinars 301!
/webinars/x /webinars 301!
/webinars/y /webinars 301!
/webinars/z /webinars 301!
/webinars/anything-here /webinars 301!

How do I make the first rule work and make a single rule that would apply to the rest? I have a thousand URLs and I dont want to create a separate rule for each if there is a way to do them at once.


Well, that depends what each URL is, there won’t be a one-size-fits-all :smile:

If you’ve got /webinars/amsterdam going to /custom/url/here and
/webinars/berlin going to /another/even/randomer/link, we can’t create a pattern and there won’t be a one-size-fits-all rule.