Help with a redirect syntax


#1

Hi all,

Just a quick help with redirect json syntax and somehow this is elluding me (the variables part, as I am not a developer):

I want to redirect from my former blog all articles from:
domain.com/category/article
to the new Ghost format of
domain.com/article
I’ve tried this:
{
“permanent”: true,
“from”: “^([A-Za-z0-9\-]+)(\/?)$”,
“to”: “/$1/”
}
But it is not working…
Later edit: made it to work, but again manually:
{
“permanent”: true,
“from”: “^others/([A-Za-z0-9\-]+)”,
“to”: “/$1/”
},
As if I were to replace “others” with .* it would go into a redirect loop.

But then…
{
“permanent”: true,
“from”: “^personal/([A-Za-z0-9\-]+)”,
“to”: “/$1/”
},
doesn’t seem to work (:boggled:) as it seems only the first rule in the list works and none of the following ones.

Later edit: adding a / (i.e. ^/personal) seems to have solved the issue.

I’ve done the categories manually, i.e. from
domain.com/category
to
domain.com/tag/category
but this could have been done with a simple regex as well.
{
“permanent”: true,
“from”: “^\/category/technology(\/?)$”,
“to”: “/tag/technology/”
},
(this works)

The examples in the docs (https://docs.ghost.org/v1/docs/redirects) don’t help much as they don’t give the actual result of the redirect. It would help to add in the long list of examples also what they actually do.

For example:
{
“from”: “^/post/[0-9]+/([a-z0-9\-]+)”,
“to”: “/$1/”
},
Redirects from /post/post-name to /post-name/.

Thanks!


Wordpress to Ghost Migration Problems
#2

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!


Redirect deleted tags
#3

Hey @dsecareanu I take it you managed to get this figured out :raised_hands:

Not sure if you have seen this, but our docs (which for sure need an overhaul) have a “suggest edits” button. If you’d like, you can submit suggestions for what information you think is missing from the page.

It’s a hard thing to document cos it depends on how well people know regex, but there’s really not any other way to do redirects!


#4

@Hannah, I’ve submitted some edits :slight_smile:, but since I’m not sure what some of the examples describe I’ve left them under “other examples” category. I also tried to restructure de page content a little bit to make it more logical in terms of how it flows and to provide some little extra bits of info that I had to figure out on my own (not being familiar with .json file formats).

Check it out and let me know if it makes sense :smile:.

Thanks!


#5

@dsecareanu

I’ve merged your suggestions and corrected/extended the redirect page a little here and there. Thanks for your time!


#6

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.