0

目前我正在尝试从 root.com/robots.txt 重定向到 beta.root.com/robots.txt。

这目前不起作用,知道为什么吗?:

{
  "version": 2,
  "alias": ["root.com"],
  "routes": [
    {
      "src": "/(.*)",
      "status": 301,
      "headers": { "Location": "https://beta.root.com/$1" },
      "dest": "/$1"
    }
  ]
}
4

1 回答 1

2

dest如果您不打算代理/重写请求,则不应使用。

由于您希望客户端重定向,因此您只需要标头即可。

{
  "version": 2,
  "routes": [
    {
      "src": "/robots.txt",
      "status": 301,
      "headers": { "Location": "https://beta.root.com/robots.txt" }
    }
  ]
}

如果要重定向所有内容,请使用通配符:

{
  "version": 2,
  "routes": [
    {
      "src": "(.*)",
      "status": 301,
      "headers": { "Location": "https://beta.root.com$1" }
    }
  ]
}

查看文档

2020 年更新

您现在可以使用redirects它更容易一些。

{
  "redirects": [
    { "source": "(.*)", "destination": "https://beta.root.com$1" }
  ]
}

查看文档

于 2019-08-29T16:57:55.280 回答