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

**URL:** <https://forum.ghost.org/t/routes-yaml-could-not-parse-yaml-duplicated-mapping-key-error/36584>\
**Category:** Themes\
**Created:** [February 22, 2023, 1:09am UTC](https://forum.ghost.org/t/routes-yaml-could-not-parse-yaml-duplicated-mapping-key-error/36584 "2023-02-22T01:09:56Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![MorganM](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/morganm/32/15233_2.png) [@MorganM](https://forum.ghost.org/u/MorganM)\
**Post date:** [February 22, 2023, 1:09am UTC](https://forum.ghost.org/t/routes-yaml-could-not-parse-yaml-duplicated-mapping-key-error/36584/1 "2023-02-22T01:09:56Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![mjw](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/mjw/32/30781_2.png) [@mjw](https://forum.ghost.org/u/mjw)\
**Post date:** [February 22, 2023, 9:43am UTC](https://forum.ghost.org/t/routes-yaml-could-not-parse-yaml-duplicated-mapping-key-error/36584/2 "2023-02-22T09:43:08Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![RyanF](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/ryanf/32/17448_2.png) [@RyanF](https://forum.ghost.org/u/RyanF)\
**Post date:** [February 22, 2023, 9:12pm UTC](https://forum.ghost.org/t/routes-yaml-could-not-parse-yaml-duplicated-mapping-key-error/36584/3 "2023-02-22T21:12:58Z")

</div>

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:

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

```

---

<div class="post-metadata">

**Author:** ![MorganM](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/morganm/32/15233_2.png) [@MorganM](https://forum.ghost.org/u/MorganM)\
**Post date:** [February 22, 2023, 9:14pm UTC](https://forum.ghost.org/t/routes-yaml-could-not-parse-yaml-duplicated-mapping-key-error/36584/4 "2023-02-22T21:14:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![RyanF](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/ryanf/32/17448_2.png) [@RyanF](https://forum.ghost.org/u/RyanF)\
**Post date:** [February 22, 2023, 9:46pm UTC](https://forum.ghost.org/t/routes-yaml-could-not-parse-yaml-duplicated-mapping-key-error/36584/5 "2023-02-22T21:46:39Z")

</div>

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

> **[Ghost Themes - Dynamic URLs & Routing](https://ghost.org/docs/themes/routing/#redirects)**
>
> Build dedicated URL structures using Ghost's dynamic routing system, for custom homepages, podcasts, categories and more.

---

<div class="post-metadata">

**Author:** ![mjw](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/mjw/32/30781_2.png) [@mjw](https://forum.ghost.org/u/mjw)\
**Post date:** [February 22, 2023, 11:26pm UTC](https://forum.ghost.org/t/routes-yaml-could-not-parse-yaml-duplicated-mapping-key-error/36584/6 "2023-02-22T23:26:58Z")

</div>

> [@RyanF](#):
>
> …it’s an outdated format in Ghost.

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

For reference:

> **[Implementing redirects in Ghost](https://ghost.org/tutorials/implementing-redirects/)**
>
> Avoid broken links by redirecting old URLs to new ones. In this tutorial, learn everything you need to know about Ghost's redirect process.

---

<div class="post-metadata">

**Author:** ![MorganM](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/morganm/32/15233_2.png) [@MorganM](https://forum.ghost.org/u/MorganM)\
**Post date:** [February 23, 2023, 12:01am UTC](https://forum.ghost.org/t/routes-yaml-could-not-parse-yaml-duplicated-mapping-key-error/36584/7 "2023-02-23T00:01:05Z")

</div>

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