Is it possible to simply create a hierarchical URL structure within the Page URL for pages?

I’ve been trying to wrap my brain around content collections and channels but I’ve concluded that the easiest way to build a hierarchical URL structure would be to simply specify it within the Page URL for a page. For instance, for a games page, my Page URL would simply be /games/ as Ghost currently allows. However, when adding a page for a specific game, I would like to specify /games/game-title/ instead of being forced to a root URL of /game-title/. So in other words, be able to include “/” within the Page URL. Is this possible with a Ghost code modification?

Examples:

Current limitation
/page-url/ < Forced to be at root

Hoping to accomplish
/specify-whatever-i-want/including-unlimited-subcategories/page-url/ < Allowing “/” to be specified within the Page URL field

1 Like

Technically you can do this with the routes.yaml file, but it’s a hassle since you have to create a structure for every single page you’d want to create. I’ve written a post in this forum about having a base url for pages and posts, to get rid of this issue, but I have no idea how interesting that is for the developers of Ghost.

Thank you greatly for your feedback! Within the routes.yaml file, where do I specify the URL for each page? Would it be within the Collections section? I’m really struggling with understanding Collections and Channels. I don’t mind a bit with hard coding a URL for each page. I just need to know where and how to do it within the routes.yaml file. I’ve read though the manual and help section, but nothing covers this need. However, I am super happy that this is possible!

In the routes section. Here’s an example:

routes:
 /: 
  template: custom-template-I-installed
  data: page.homepage-name

 /services-solutions/some-service/:
  template: page
  data: page.some-service

collections:
  /blog/:
    permalink: /blog/{slug}/
    template: index
    
taxonomies:
  tag: /topic/{slug}/
  author: /author/{slug}/

The first grouping causes a page called homepage-name to be served at / , using a custom template installed in the theme.

The second grouping causes the some-service page to show up at /services-solutions/some-service. You could duplicate this to make other pages that route to /services-solutions/some-other-service.

The collections section puts the blog at /blog/, since / goes to the landing page instead of the blog index page. Blog posts will be at /blog/some-post-name.

And then taxonomies is pretty standard, except in this example I’m calling my tags ‘topics’ instead.

Now, having given you an example that does what you want, I guess I’ll back up a little bit and ask why you want it? What’s accomplished by having the illusion of nested folders? Is it actually better to have /services-solutions/some-service versus /services-solutions-some-service? It seems like it’d have to be an SEO argument, because I’m positive mobile users won’t notice the difference, and I’m not sure desktop users will, either! This is clearly something some users want, but I have yet to see a convincing explanation for /why/, other than being used to subpages on some other blogging platforms.

Editing the routes.yaml is a pain. Every time you touch it, there’s an opportunity to accidentally mess it up in some way that breaks routing. I do it for homepages, absolutely. But I don’t see the point to making a fake directory structure, especially if you’re planning to create new pages regularly!

Providing a contextual relationship is really good SEO. For example, in my upcoming “Software” section, I will have multiple types of software featured. Let’s say for example, my upcoming 3D Rendering category. By specifying a URL structure with /software/3d-rendering/ search engines see a contextual relationship that would otherwise not be there if it were to simply be at root. Specifying contextual relationships is powerful in terms of search engine optimization. It goes back to the old dilemma that search engines had many years ago with the introduction of the Java programming language. At the time, it was a huge problem. Was the page about coffee or programming? Now granted, things have come a long way since then, but why rely on assuming that search engines will properly rank your content in it’s appropriate genre by keeping them guessing? Plus, I will have breadcrumb navigation at the top of my pages soon. Maybe I am just old school lol but my SEO skills are second to none in terms of organic search results. Just getting started with my digital magazine though so only time will tell.

I tried the following:

/games/lords-of-the-fallen/:
template: default
data: page.lords-of-the-fallen

However, it doesn’t work:
https://visualdynamics.com/games/lords-of-the-fallen/

Do I need to restart Ghost?

my routes.yaml is the following:

routes:

/games/lords-of-the-fallen/:
template: default
data: page.lords-of-the-fallen

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

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

I figured it out. I was specifying the incorrect template file. Works great! Yay!!!

2 Likes

Glad you got it working, @visualdynamics !

I’m curious about the folders vs files thing and whether it matters for SEO. Do you have a link? The best I found was this: How Do I Name Folders & Product Files Effectively? , which says it doesn’t matter, but is admittedly five years outdated. I’d like to better understand why folders matter.

For anyone looking for breadcrumbs, they’re pretty easy to add (once you edit the theme), using the page’s primary_tag and perhaps the second tag on the post also, depending on how ‘deep’ you want them to look.

And I’m sure you know this, but for anyone finding this thread in the future: One solution if you’re determined to have a folder structure but don’t want to edit routes.yaml every time you add a page is to switch to creating posts instead of pages. Then you can set up routing on those posts so that they appear at /{primary_tag}/{slug} , for example. Because posts and pages have the same helpers and functionality (except this routes.yaml limitation), that can be a pretty good option. AND it gets your your ‘pages’ (actually posts) into the Ghost search results, too.

The link that you provided has good advice in my opinion. I don’t have any links to reference, only 20+ years of SEO experience.

I rebuilt the Lords of the Fallen content into a post instead of a page, but how do I specify /{primary_tag}/{slug} and where? The page URL field on the post settings still forces a root URL. Does a route still need to be specified within the routes.yaml file and if so, where should it be specified? I read in the documentation that additional taxonomies is not possible, so I’m a bit confused.

I got it to work by simply specifying “post” instead of “page” within the routes.yaml file.

data: post.lords-of-the-fallen

The only drawback that I can see is that Ghost still points to the original “Post URL” value and then routes upon page load. This creates a significant side effect where if anyone clicks on the Social Media icons to share the page, the URL within the share link is the “Post URL” value and not the routed URL. This feels more like a simple redirect and not a URL directive. I would really like the links to contain the route value and not the “Post URL” value. Does anyone know if this is possible? This brings me back to my original idea of simply being able to specify “/” within the “Post URL” field on the post itself. Simply specifying “games/lords-of-the-fallen/” within the “Post URL” field and the “/” not being stripped out. I’m hoping very much that this is possible.