John Siu Blog

Tech - Business Tool, Personal Toys

Ghost Blog Redirect for WordPress Migration

☰ Table of Content

In my earlier post Lighttpd url.redirect and changing WordPress permalink structure, I talk about the issue when permalink structure is changed.

New Issue

When migrating from WordPress to Ghost, the permalink structure is changed again, from

1
https://johnsiu.com/index.php/sample-post/

to

1
https://johnsiu.com/sample-post/

Solution

Ghost development team provided a perfect and simple solution in version 0.11.4, the redirects.json. The official document is here.

redirects.json need to be placed in <Ghost root>/content/data/.

The redirects.json for my site is as follow

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
[
  {
    "permanent": true,
    "from":"^/index.php/[0-9]{4}/[0-9]{2}/[0-9]{2}/(.*)$",
    "to":"/$1"
  },
  {
    "permanent": true,
    "from":"^/index.php/category/(.*)$",
    "to":"/tag/$1"
  },
  {
    "permanent": true,
    "from":"^/index.php/(.*)$",
    "to":"/$1"
  }
]

The above will take care of the following redirects:

  • https://johnsiu.com/index.php/YYYY/MM/DD/<post>/ to https://johnsiu.com/<post>/
  • https://johnsiu.com/index.php/category/<tag>/ to https://johnsiu.com/tag/<tag>/
  • https://johnsiu.com/index.php/<post>/ to https://johnsiu.com/<post>/

Done!! ✌️

John Siu

Update: 2020-08-28
comments powered by Disqus