Can we use "www.domain.com/home/example-text" link in Ghost

Hey,

I am moving from Squarespace to Ghost and there’s one big problem that I have encountered. In Squarespace my post links were like this:

www.mydomain.com/home/text-text-text

But after the import, in Ghost the URL is set to this:

www.mydomain.com/text-text-text

Is there anyway to get the URL as it was original. Because if that can’t be done, it will break all my links which will prevent me from making the move.

it is certainly possible, read this documentation page:

Hey,
Thanks for the reply. As far as I can understand it, it’s about collection pages. How can I change it for individual posts. Understand I am not technical savvy. So please explain as such.

The documentation previously mentioned does contain the information that you are looking for. In order to implement it, you will need to edit your site’s routes.yaml file. The first couple of paragraphs here has instructions for such - it’s in your site’s admin page. Download the file, open it in any text editor, make the changes, then upload it through the admin site. No restarts needed.

As for editing the file, you will need to modify the / entry under the collections section. For your case, it may look like this:

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

Hey,

I tried and got the URL part working. I created two collections but now the homepage is showing 404 page not found error.

Yes, the homepage (domain.com/) is now not routed to anything.

You probably want it to be the index page as well? You can do that under the routes section. I think the simplest thing to do is this:

routes:
  /: index

So, keep in mind that this will point your / route to the index.hbs file in your theme. Similarly, if you have template: index under your collections, it will also point to that file, effectively creating duplicate pages. It can all be fully customized. Alternatively, you could make a redirect. In your case, it might make sense to redirect domain.com/home to domain.com/. There is a redirect file near the routes.yaml file which you can edit. Your may look like this:

[{
  "from": "https://domain.com/home/" ,
  "to":  "https://domain.com/",
  "permanent": true
}]

You may want to leave permanent to false until you’re sure what you want to do, as it will create a 301 redirect which takes some steps to remove from your browser.

Hope this helps.

Hey thanks for taking time to answer me. It’s not working for me. Here’s my problem. I am creating three collections.

collections:
  /home/:
    permalink: /home/{slug}/
    template: home
    filter: primary_tag:home
collections:
  /news/:
    permalink: /news/{slug}/
    template: news
    filter: primary_tag:news
collections:
  /reviews/:
    permalink: /reviews/{slug}/
    template: reviews
    filter: primary_tag:reviews

I entered all this in my routing file. Now it is working perfectly for blog posts. It’s creating the original URL that I wanted (Ex: www.mydomain.com/news/slug).

But now my (www.mydomain.com) is pointing to nothing. I want the (www.mydomain.com) to show all the posts (from all three collections), which it was doing before I used the routing method.

Is it possible? If so, how?

Ok, I understand your use case better now - that’s a really straightforward fix.

I mentioned above that you can use:

routes:
  /: index

to point your / (your homepage) to the index file, which is normal functionality. The index page will not do any filtering by default, so all of your posts will be there. Just add that to the top of your routes.yaml file and you’ll have what you want.

Oh, also, you don’t need to repeat the collections: line. Once is correct, and the three entries under it.

There is no need for redirects, so clear that file out as well.

Hey,

I added the

routes:
  /: index

file as you suggested. It removed the 404 error but now home page is blank and showing nothing.

I’m not quite sure what’s happening now. As far as I can tell, that should work fine. I suppose for a sanity check you could be more explicit by listing the template on a separate line. The semantic should be the same, though.

That being said, I suggest having some place for all other posts than the three primary_tags you mentioned to call home (at least, if you ever intend to post without one of those primary tags. if not, it won’t hurt anything). So, maybe you move the / to collections, with a filter like: filter: primary_tag:-[home,news,reviews] The - after primary tag forms an exclusionary filter, while the brackets indicate an ‘or’ group, so that everything inside the brackets will be excluded.

For a sanity check, here’s the whole file that I’m suggesting.

routes:
collections:
  /home/:
    permalink: /home/{slug}/
    template: home
    filter: primary_tag:home
  /news/:
    permalink: /news/{slug}/
    template: news
    filter: primary_tag:news
  /reviews/:
    permalink: /reviews/{slug}/
    template: reviews
    filter: primary_tag:reviews
  /:
    permalink: /{slug}/
    template: index
    filter: primary_tag:-[home,news,reviews]
taxonomies:
  tag: /tag/{slug}/
  author: /author/{slug}/

The taxonomies may not be necessary for you, but they’re nice to have in most cases. They’re additional URLs at which your posts can be found. Also make sure you understand how primary tags work - they are the first tag you list on each post.

If this doesn’t work, I must ask - did you change anything with you theme, specifically the index file? That may be why it was showing a blank page. As I mentioned, I really think the above should have worked.

Still the same issue. And just to make sure that I have not ruined something, I deleted the publication and started with a fresh publication. I uploaded the routes.yaml file that you wrote above. But it’s the same thing again. All the collections are working perfectly but the main home page is empty.

Anyway thanks for taking out the time to respond to this problem. I myself don’t know what’s going wrong here.

I think what you’re looking for is Channels. Channels in Ghost let you create list pages that are a combination of all posts from across your site, without removing them from their original collections. Here’s how you would add a Channel to :

routes:
  /:
    controller: channel
    template: index

collections:
  /home/:
    permalink: /home/{slug}/
    template: home
    filter: primary_tag:home
  /news/:
    permalink: /news/{slug}/
    template: news
    filter: primary_tag:news
  /reviews/:
    permalink: /reviews/{slug}/
    template: reviews
    filter: primary_tag:reviews

With this setup you collections will still appear at /home/, /news/and /reviews/ will still be their own collections and still apply the permalink structure but the home page (/) will list all the posts from the site.

Hope this helps!

Yes. It totally solved my problem. Thanks a ton! Just a quick question, can this also be done using internal tags?

To place posts into their respective collections you’ll need to prefix the tag with a # when you add it to the post. Then you’ll need to define the collections like so:

routes:
  /:
    controller: channel
    template: index

collections:
  /home/:
    permalink: /home/{slug}/
    template: home
    filter: 'tag:hash-home'
  /news/:
    permalink: /news/{slug}/
    template: news
    filter: 'tag:hash-news'
  /reviews/:
    permalink: /reviews/{slug}/
    template: reviews
    filter: 'tag:hash-reviews'

Couple of things to take note here; Firstly I’ve switched to using tags rather than primary tag, this is so I can use the primary tag for other things in my site. Additionally internal tags referenced in the routes file need to be prefixed with hash- to mirror the # used on the post.

Furthermore, if you wanted to use internal tags to selectively show posts on the homepage you can as well:

routes:
  /:
    controller: channel
    template: index
    filter: 'tag:hash-homepage'

collections:
  /home/:
    permalink: /home/{slug}/
    template: home
    filter: 'tag:hash-home'
  /news/:
    permalink: /news/{slug}/
    template: news
    filter: 'tag:hash-news'
  /reviews/:
    permalink: /reviews/{slug}/
    template: reviews
    filter: 'tag:hash-reviews'

In this second example any time a post has the tag #homepage applied it’ll show up on the home page.

Hope this helps!

1 Like

I will try it out. Thanks for all your help. You have solved all my problems. Hopefully I can set up everything and move to Ghost in the coming week.

1 Like

No problem! The community is here to help :blush:

1 Like