Thingamajig
Thingamajig

Reputation: 4465

How can I set up a redirect with Zeit's Now 2.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"
    }
  ]
}

Upvotes: 0

Views: 764

Answers (1)

styfle
styfle

Reputation: 24610

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

Upvotes: 3

Related Questions