'Redirect URL to another domain with same path in Ghost CMS redirects.json

I try to use Redirect.json for redirect URLs in ghost CMS. I use this in redirect.json file

[{
        "from": "/([a-zA-Z\d.-]+)",
        "to": "https://blog.anotherdomain.com/$1",
        "permanent": true
}]

its redirect to another domain but in URL its printing $1 its unable to fetch URL path please help me to solve this



Solution 1:[1]

Solution

I found the issue with your redirect! issue missing trailing "/" and unescaped slash

from

/([a-zA-Z\d.-]+)

missing slash and unescaped slash

to

/([a-zA-Z\\d.-]+)/

fixed version

full copy and paste

[{
    "from": "/([a-zA-Z\\d.-]+)/",
    "to": "https://blog.anotherdomain.com/$1",
    "permanent": true
}]

Reference for future people

Go to /ghost/#/settings/labs then click on upload redirects.json

photo showing the location of the upload redirects button

modify the following code to match your blog

[{
    "from": "/([a-zA-Z\\d.-]+)/",
    "to": "https://<YOUR_GOES_HERE>.com/$1",
    "permanent": true
}]

More information on ghost redirects

https://ghost.org/docs/tutorials/creating-content-collections/

Solution 2:[2]

@wisemonkey's answer is completely correct (and worked for me as well), but incomplete. You'll also need to add

{
    "from": "/",
    "to": "https://<YOUR_GOES_HERE>.com/",
    "permanent": true
}

... to redirect the homepage, which isn't caught in the first regex. So the final redirects.json file will look like:

[{
    "from": "/([a-zA-Z\\d.-]+)/",
    "to": "https://<YOUR_GOES_HERE>.com/$1",
    "permanent": true
},
{
    "from": "/",
    "to": "https://<YOUR_GOES_HERE>.com/",
    "permanent": true
}]

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 wisemonkey
Solution 2 sharedphysics