Learn Ghost

Young blogging platform build on tope of node.js for fast loading speed and easy scalability!

• Last Updated: 05/15/2020
• ( 3 minutes reading )

How to customize the URL structure of your Ghost blog

Introduction

Dynamic routing is the system that maps the URL structure of your Ghost to your theme and data within the website itself. By default, it is preconfigured; however, Ghost provides you the flexibility to customize it so you can give your website’s structure a unique and robust look. In this article, we are going to cover the way you can customize your routes and which file are these dynamic routes located in. Let’s begin!

 

Accessing the Labs 

For a start, you have to log into your Ghost Admin Dashboard. To do so, please open your favorite browser and enter your domain name, followed by "/ghost". For example:

  • ghost.hostarmadatutorials.com/ghost

 

Login page

 

After logging in, please point your attention to the left side of the screen. You will see a sidebar, and from the listed choices, you will need the “Labs” option.

 

Access Labs

 

When selected, you will be redirected to a page containing all sorts of tasks you can perform on your blog. 

 

Routes functionality

 

Scroll down to the bottom of the page, where you will see the “Beta features” section, and under it, you will find the “Routes” row.

 

Adding Dynamic Routes

The file where the routes for your blog are held is inside the /home/user/websiterootdir/content/settings/routes.yaml file. If yo you are not sure which is the root directory of your blog, please check our knowledge base article on Which is my website’s root directory.

You can directly go and edit that YAML file on the server and set your new routes. Afterward, you have to restart your Ghost blog for the changes to take effect. This is why we recommend using the option from your Dashboard, as it eliminates the need for restarting the application.

To begin setting up your new routes, please download the current file locally using the “Download current routes.yaml” link, located under the “Upload routes YAML” button.

 

Download Current Routes YAML file

 

When you download the file and open it for editing, the default content will look like this:

 

routes:



collections:

  /:

    permalink: /{slug}/

    template: index



taxonomies:

  tag: /tag/{slug}/

  author: /author/{slug}/

 

The homepage of your blog can be seen as a reverse-chronological list of your posts, with each post defined by its own URL represented by a {slug} parameter. For example -  best-post-ever. Additionally, there are archives of posts arranged by author and tag. Let’s give a really basic example.

Let’s say you want to put all your posts in yourblog.com/posts/yourpost, instead of the standard yourwebsite.com/yourpost. To do so, simply edit the permalink: /{slug}/ part of the file to permalink: /posts/{slug}/ and you are all set!

If you want to do even cooler stuff with the routes, we recommend checking the official YAML website, which has great reads regarding the structure and syntax of YAML files.

Once the file is saved, you can upload it through your Ghost dashboard by clicking the “Upload routes YAML” button inside the “Routes” row.

 

Download Current Routes YAML file

 

Clicking on the ”Upload routes YAML” will open a popup window, allowing you to select the YAML file you just edited. The changes should have taken effect immediately, and you can test them after clearing your browser’s cache.

 

There you have it! The way to change the structure of your URLs on your Ghost blog. We hope that this tutorial was useful, and you are now well-aware of how to change the structure using creative and unique routes!

 

 

...
Sebahat
Content Marketing Specialist

Sebahat is a young and bright woman who has become an invaluable part of our team. She started as a Customer Care Representative, mastering that role and, along the way, growing into a tech-savvy individual who is well acquainted with every support layer of the company. Driven by her aim to improve our customers’ experience constantly, she is committed to enhancing the extraordinary support we deliver.