Use routes to route site.com/tag/podcast to site.com/podcast

I’m attempting to route Domain error to Domain error using the route.yaml. After following the documentation I create the route.yaml shown below, but when I go to the url the collection is empty. Any suggestions? Thank!

Here is the route.yaml configuration I have.

routes:

collections:
  /:
    permalink: /{slug}/
    template: index
  /blog/:
    permalink: /blog/{slug}/
    template: blog
    filter: tag:blog
  /podcast/:
    permalink: /podcast/{slug}/
    template: podcast
    filter: tag:podcast

taxonomies:
  tag: /tag/{slug}/
  author: /author/{slug}/

Tag setting:

Tags on post are:
Getting Started, Podcast

When you create a collection you need to ensure the filtering parameters are unique. In your case the first collection isn’t filtering for anything, so all posts match that criteria. After that nothing will be left to match “blog” or “podcast” as collections treat posts exclusively (they can only exist in one collection).

If you want your home page to have all post types and only show podcasts on /podcasts/ and blog posts on /blog/ then you’ll want to use Channels instead:
https://ghost.org/docs/api/v3/handlebars-themes/routing/channels/

But if you want to split posts to only show blog posts on /blog/ and podcasts /podcasts/ and then have the remaining posts on the home page then you’ll want to use Collections more like this:

collections:
  /:
    permalink: /{slug}/
    template: index
    filter: 'primary_tag:-[blog,podcast]'
  /blog/:
    permalink: /blog/{slug}/
    template: blog
    filter: 'primary_tag:blog'
  /podcast/:
    permalink: /podcast/{slug}/
    template: podcast
    filter: 'primary_tag:podcast'

Couple of things to note here: I’m using minus - to exclude blog posts and podcast posts from the index, and I’m using primary_tag to filter posts. The primary tag is the first tag applied and will always be unique. More info here in our docs:

Hope this helps!

2 Likes

I got it working! I’ll be purchasing ghost and migrating my blog soon. Thank you so much for the detailed reply @DavidDarnes!

1 Like

Alternatively, if you just want the route for all Tag pages to be /{tag_slug}/ instead of /tag/{tag_slug} you can modify your Taxonomies:

taxonomies:
  tag: /{slug}/
  author: /author/{slug}/
1 Like