Routes.yaml 'Could not parse YAML: duplicated mapping key' error

when uploading my edit: redirects.yaml file, I’m receiving the error message ‘Could not parse YAML: duplicated mapping key’. I’m pretty sure it’s because I’m trying to reroute multiple URLs to one destination, as per the below

301:
/tag/online-course: /tag/courses
/tag/online-course/video-lessons: /tag/courses
/tag/the-online-course: /tag/courses
/course: /tag/courses

Is there a way to format rerouting in this case, so that Ghost doesn’t get upset?

These are redirects, and shouldn’t use routing. I added these using redirects.json…

[
  {
    "from": "^/tag/online-course $",
    "to": "https://your.domain/tag/courses",
    "permanent": true
  },
  { "from": …
  }
]

YAML is whitespace sensitive, which means that spaces affect the syntax of the file.

My guess here is that you need two spaces before each of your redirects:

301:
  /tag/online-course: /tag/courses
  /tag/online-course/video-lessons: /tag/courses
  /tag/the-online-course: /tag/courses
  /course: /tag/courses
1 Like

Argh, sorry. I’m working in redirects.yaml. (I’ve been working on routes.yaml so much I just type it automatically now)

This is awsome, thank you! I’ll give it a try

It should also be added that while JSON will work, it’s an outdated format in Ghost.

From the docs:

If you’ve updated your site from an earlier version (prior to 4.0), your redirects may be in JSON format. Both formats are still supported, but JSON support will be removed in a later version

2 Likes

I missed that, so I guess I need to update my site to use redirects.yaml.

For reference:

1 Like

Solved! Fixed spacing and also found a duplicate entry. Thanks folks

2 Likes