📣🚀🐣🌼 Sonic Bloom - Spring Sale! | Exclusive offers for Cloud Shared Hosting - 70% OFF | Starting from $3.99/mo
Learn Ghost

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

• Last Updated: 05/18/2020
• ( minutes reading )

How to configure Redirects on your Ghost blog

Introduction

Redirects are an essential part of web development. When configured, it will forward a particular URL or a domain name to a different URL or domain. The most common usage of URL redirection is done when you want to either move content from one page/URL to a different one or completely change the domain name of your website. Typically, these redirects are implemented via specific rules based on the webserver (Apache, Nginx), however, in this tutorial, we will focus on the way to set up redirections using the Ghost admin and JSON files. Let’s begin.

 

Accessing the Redirects functionality

In order to access the “Redirects” functionality, 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

 

Once logged, please point your attention to the left side of the screen. You will see a sidebar, and from the listed choices, please click the “Labs” option.

 

Access Labs section

 

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

 

Redirects settings

 

Please scroll down to the “Beta Features” section. Under it, you will see the “Redirects” row.

 

Implementing a Redirect

As we mentioned earlier in this tutorial, we are going to be setting up redirects using a JSON file called “redirects.json”, which we are going to upload in the Ghost admin. By default, there will be no redirects, and the “redirects.json” file will contain two closed square brackets “[]”. You can download it locally by clicking on the “Download current redirects” link in the “Redirects” row.

 

Download redirects.json file

 

After downloading the file, you can start iterating upon it by adding the redirects you need in between the mentioned brackets “[]”. Here is the most basic structure of this JSON file you can use:

 

{

  "from": "/current-url/" ,

  "to":  "/new-url/",

  "permanent": false | true

}

 

Of course, each entry needs to be separated with a comma “,” with the last one remaining without, just like the above example shows. For you to get a better understand, let’s decipher the above code snipped and give it a simpler meaning:

  • from - In this field, you are going to define the current URL.
  • to - In this field, you are going to specify the new URL you wish the current one to redirect to.
  • permanent - This requires either a true or false statement, which will set either a 301 permanent (true) or a 302 temporary (false) redirect.

Here is an example of what the redirects.json should look like.

 

[{

    "from": "/tutorials/",

    "to": "/hostarmada-tutorials/",

    "permanent": true

}]

 

You may also utilize regular expressions inside this JSON file. Here is an example.

 

[{

    "from": "^\\/blog/oldhostarmadapost(\\/?)$",

    "to": "/blog/new-postname",

    "permanent": true

}]

 

Basically, what this will do is it will see if the pattern matches ghost.hostarmadatutorials.com/blog/oldnameofpost/, and if it does, it will redirect it to ghost.hostarmadatutorials.com/blog/newpost/. Let’s give a bit more information about the used expressions.

  • ^\\/blog - This will match anything with the /blog/ structure.
  • (\\/?)$ - This regex will match anything after the /blog/oldnameofpost/ structure that contains or does not contain a trailing slash at the end. 

Additional usage of the redirection functionality in Ghost could involve restructuring your posts; however, we recommend using dynamic routing instead.

Once you have made the desired changes regarding the redirects you want on your blog, you need to upload the redirects JSON file. To do so, please click the “Upload redirects JSON” button, located on the far right side of the “Redirects” row.

 

Upload modified redirects.json file

 

This will open a window allowing you to select the file from your local PC or device. Once uploaded, please make sure to clear your browser’s cache before testing the newly implemented redirects!

 

There you have it! The way to set up redirects on your Ghost blog using a “redirects.json” file. If you have issues settings this on your end, you could ask our technical support team for assistance. They are 24/7 available at your disposal, through the ticketing system in your Client Area.

 

 

...
Sebahat
Technical Support Captain

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.