Ghost Native URL redirection

Picture for the post Ghost Native URL redirection

Ghost comes with a very useful feature called Redirection. It handles the Redirections of URLs natively so that you don't have to deal with this thing from the server end.

A Practical Use-case of redirection is you have moved your blog from WordPress to Ghost. Now your URLs became from [domain].com/post/year/post-name/ to [domain].com/postname/. So now you wanna redirect your old URLs to the new URL structure. And this thing can be easily done with Ghost Redirects Feature. to do that follow the steps

  • Log into the Ghost admin section of your blog and click on Labs.
  • Scroll down to the bottom and click on Download current Redirects.
  • Open the file in a Code Editor. eg VScode or notepad.
  • By default, it will only have [] in the file. Inside here you can add as many redirects as you wish using standard JSON formatting.

Each redirect will have a from, to, and whether it is permanent or not.

For a single post to post redirect:

[{
     "from": "/some-old-post/",
     "to": "/some-new-post/",
     "permanent": true
 }]

For multiple posts

[{
     "from": "/some-old-post/",
     "to": "/some-new-post/",
     "permanent": true
 },
 {
     "from": "/some-old-post2/",
     "to": "/some-new-post2/",
     "permanent": true
 },
 {
     "from": "/some-old-post3/",
     "to": "/some-new-post3/",
     "permanent": true
 }]

The to and from can also take regex examples. Here is an example from on how to redirect your posts from [domain].com/post/year/post-name/ to [domain].com/postname/

[{
     "from": "^/post/[0-9]+/([a-z0-9\\-]+)",
     "to": "/$1/"
 }]

Once you have created your file, go back over to your Ghost admin, and click on the 'Upload redirects JSON' button, and upload your JSON file. Unless there are any errors, it will take effect immediately.