Branch: master
Find file History
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
.nowignore Redirect example added (#159) Nov 20, 2018
README.md Update redirect example to be a little more clear (#234) Jan 20, 2019
now.json Update the redirect example to be simpler (#224) Jan 12, 2019

README.md

Redirect

In this example we will be deploying a simple redirect from a www domain to a naked one. This will be an entirely separate deployment from your main one. You just need to deploy it one time and then you can forget about it.

Deploy with Now

Create a new folder on your local machine and create a new now.json file. To redirect, you only need to use the routes property of a now.json file (no need to have a builds property in there, since it's just doing a redirect).

By adding the version key to the now.json file, we can specify to use the latest Now Platform version to use routes.

Following that, we can add a routes property that sets a status of 301, a permanent redirect, and sends a location header of the redirect destination:

{
    "version": 2,
    "alias": [
        "www.example.sh"
    ],
    "routes": [
       { "src": "/(.*)", "status": 301, "headers": { "Location": "https://example.sh/$1" }}
    ]
}

Visit our documentation for more information on the now.json configuration file.

Finally, deploy the redirect using Now CLI:

now

Once the deployment is created, you can alias it to the defined alias in the now.json file by running:

now alias

Now, when visiting either the alias (www.example.sh) or deployment URL, the visitor will get redirected to the location set via the routes in the now.json file.