Custom Routes Not Working

Hi everyone,

I’m trying to set up custom dynamic routing on my Ghost website, but I’m running into some issues. I want to create a custom route for a specific post collection and apply a different template to it. Here’s what I’ve done so far:

  1. Updated the routes.yaml file with the following configuration:
routes:  
  /custom-path/:  
    template: custom-template  

collections:  
  /blog/:  
    permalink: /blog/{slug}/  
    template: blog  
    filter: tag:-custom  

  /custom-collection/:  
    permalink: /custom/{slug}/  
    template: custom-template  
    filter: tag:custom  

taxonomies:  
  tag: /tag/{slug}/  
  author: /author/{slug}/
  1. Restarted Ghost and verified that the routes.yaml file is valid.

The problems I’m facing:

  1. The /custom-path/ route displays a 404 error even though I have posts with the required tag:custom.
  2. Posts that should belong to the /custom-collection/ are still appearing in the /blog/ collection.
  3. The custom template isn’t being applied to any posts under the custom collection.

What I’ve tried so far:

  • Clearing the cache and restarting Ghost multiple times.
  • Verifying that the custom-template.hbs file exists in the theme folder.
  • Ensuring the posts have the correct tag assigned.

I’d appreciate any advice on:

  1. Troubleshooting dynamic routing issues in Ghost.
  2. Debugging why the custom route is not being recognized.
  3. Whether my routes.yaml setup has any mistakes or missing configurations.

Thanks in advance for your help!

1 Like

Just to confirm, you are uploading your routes file through ghost > settings (gear icon) > labs, right?

1 Like

Thank you for responding! Yes, I uploaded the routes.yaml file through Ghost > Settings (gear icon) > Labs and made sure the upload was successful. I also verified that there were no validation errors during the upload process.

If there’s any additional step or configuration I might be missing after uploading the file, please let me know. I’d greatly appreciate further guidance on this issue!

I’m wondering if your attempt to anonymize things is hiding something important, like an incompatible character that’s messing up the parser.

This looks like two errors, one with the route, and a separate with the collection.

A couple thoughts:

0- if you’re self hosting, restart ghost.

1-ghost will 404 if theres a fatal template error.

2- the filename custom-whatever is for post templates and causes the templates to appear as choices in the post/page editor. If the file is actually named custom-something, and you’re using it as a replacement index page, try renaming.

3- try putting filter strings in quotes. Filter: “tag:-something”

4- pass tags as arrays, ie filter: tag:-[yourtag]