0

Currently I'm trying to redirect from root.com/robots.txt to beta.root.com/robots.txt.

This is not working currently, any idea why?:

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

1 Answers1

3

You should not use dest if you don't plan on proxy/rewriting requests.

Since you want the client to redirect, all you need is the header.

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

If you want to redirect everything, use a wildcard:

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

View Documentation

Update 2020

You can now use redirects which is a little easier.

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

View Documentation

styfle
  • 22,361
  • 27
  • 86
  • 128
  • Hi @styfle ... maybe you can help me .. I'm trying to do proxy My API it's running under `https://my-api.com/test.json` the app it's making request to `/api/test.json` so... how can I configure vercel ? That's it's what I have so far... ------------------ ``` "redirects": [ { "source": "/api/menu.json", "destination": "https://chatfood-cdn.s3.eu-central-1.amazonaws.com/fe-code-challenge-1/menu.json", } ], "rewrites": [ { "source": "/(.*)", "destination": "/index.html" } ] ``` – ridermansb Dec 26 '20 at 13:03
  • Do you know, do I have to set wildcard domain in Vercel to apply redirect? I get `DEPLOYMENT_NOT_FOUND` error. https://stackoverflow.com/questions/73031660/how-to-configure-arbitrary-subdomain-to-be-able-to-use-in-vercel – János Jul 19 '22 at 09:24