首页 > 解决方案 > 将 URL 重定向到 Ghost CMS redirects.json 中具有相同路径的另一个域

问题描述

我尝试在 ghost CMS 中使用 Redirect.json 来重定向 URL。我在redirect.json 文件中使用它

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

它重定向到另一个域,但在 URL 中打印 $1 它无法获取 URL 路径请帮我解决这个问题

标签: jsonredirectghost-blog

解决方案


解决方案

我发现你的重定向有问题!问题缺少尾随“/”和未转义的斜杠

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

缺少斜线和未转义的斜线

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

固定版本

完整复制和粘贴

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

供未来人参考

转到/ghost/#/settings/labs 然后单击上传redirects.json

显示上传重定向按钮位置的照片

修改以下代码以匹配您的博客

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

有关幽灵重定向的更多信息

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


推荐阅读