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.
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
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:
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.
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.
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.
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.
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 :
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.
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:
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: