Help with a redirect syntax

Replying to myself with the actual working redirects maybe it helps other people as well:

If you migrated your blog from WordPress to Ghost and wanted to fix the URL’s (assuming your WP permalinks were domain.com/category/), then you need to do the following:

   {
    "permanent": true,
    "from": "^/others/([A-Za-z0-9\\-]+)",
    "to": "/$1/"
},

This will redirect from domain.com/others/post-name/ to domain.com/post-name/ (the postname being a regex variable made out of letters & numbers that is afterwards called with $1).

If you want to redirect the category URL’s (i.e. domain.com/category/category-name/) if they were somehow indexed by Google, you need to do the following:

{
    "permanent": true,
    "from": "^\\/others(\\/?)$",
    "to": "/tag/others/"
},

This will redirect domain.com/others/ to domain.com/tag/others/.

I also had to redirect domain.com/category/others/ so I added this:

{
    "permanent": true,
    "from": "^\\/category/others(\\/?)$",
    "to": "/tag/others/"
},

I hope this helps :wink:.

Enjoy!

2 Likes