Changing default post routing

Greetings,

I’m migrating an existing blog to ghost and am having trouble matching the post routing. The blog I’m migrating uses a url structure like /post/example-post however ghost’s default post routing using the /example-post format. Is it possible to change Ghost’s default routing for posts? I’ve read through all of the routing docs but nothing makes sense for my use case. A single post doesn’t fit the definition of a “collection”. I thought maybe I could use the channel controller and filter to the post by slug, but this still wouldn’t set the post.url property properly. Is there a way to do this in ghost? I’m trying to avoid using redirects, or changing my url structure.

Thank you for any help.

I’m developing against the ghost:3.33-alpine docker image.

Best regards,
Nathan

Hey @NathanCobb,

The only change required would be changing the default root collection’s permalink from /{slug}/ to /post/{slug}/. Your site’s routing.yaml should look like:

collections:
  /:
    permalink: /post/{slug}/
    template: index

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

Thanks for the quick response!

Unfortunately this doesn’t seem to work as expected. When I visit the url http://localhost:2368/post/example-post for example It actually redirects to http://localhost:2368/example-post, which resolves as 404.

My routes file:

routes:

collections:
    /:
        permalink: /post/{slug}/
        template: index

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

My redirects.json file is empty.

Thank you for your help!

It worked! I didn’t record the network interactions from my first couple tests, but it appeared to be a caching issue. I created a new post to test with and it loaded properly. Thanks for your response, super helpful!

Best,
Nathan

1 Like

Confirmed it was a caching issue. I checked Disable Cache in chrome network tab and my older posts are loading as expected.