Last week i was reviewing my old blog (https://dhakshinamoorthy.wordpress.com), and noticed that all the link that i have there, that is suppose to redirect to my new blog (https://soundararajan.in) wasn't working. The reason is that the link that is put there has the following format

<domain>/blog/year/month/date/blog-title

But with the recent update of ghost the url of my blogs changed and hence none of the redirects seem to be working. The change is that they remove year, month, date from the url and started using the blog-title alone as part of the URL. Thanks to google analytics, which helped me analyse and understand the problem. Because of this i lost a bunch of users and page views. Also the users who clicks on these links gets frustrated because they don't have anywhere to go. I decided to fix these links but there were close to 80 of them, which clearly is not an option. I searched for various options from routing in reverse proxy (nginx), any code change to ghost itself , or something like a taiko script to update the source system with proper links. Then i figured out that ghost has this new feature "Redirects" which allow you to configure the source link and destination link declaratively in a JSON format which will then be used by the ghost engine to gracefully serve the blog's. The json also accepts regular expressions for source match and destination substitute. This makes it the ideal choice to go with as i can simply write a regular expression that will trim the year, month, date and return the blog-title alone. Here is how to write it.

[ {
  "from":"^/blog/\\d{4}/\\d{2}/\\d{2}/([a-z0-9\\-]*)(/)?",
  "to":"/$1",
. "permanent":true
}]