Redirects

Send visitors from one path to another with rules in lahyer.json.

lahyer.json
{
  "redirects": [
    { "source": "/old-pricing", "destination": "/pricing", "permanent": true },
    { "source": "/blog/:slug", "destination": "/posts/:slug" },
    { "source": "/docs/:path*", "destination": "https://docs.example.com/:path*", "statusCode": 301 }
  ]
}

How redirects work

  • Lahyer checks redirects before anything else, so a redirected path never reaches your files or your app, and a sleeping server app is not woken for it.
  • Rules are checked in order and the first one that matches wins.
  • The query string is kept: /old-pricing?ref=mail goes to /pricing?ref=mail.
  • Matching ignores letter case and a trailing slash. See path patterns.

Fields

FieldDescription
sourceThe path pattern to match. Required.
destinationA path starting with /, or an absolute http:// or https:// URL. It can reuse the source's :name parameters and $1, $2 for groups. Required.
permanenttrue answers 308 Permanent Redirect; false or leaving it out answers 307 Temporary Redirect.
statusCode301, 302, 307 or 308, when you need a particular status. Use it instead of permanent: setting both fails the build.

Limits

  • Up to 100 redirects per deployment.
  • A source up to 512 characters, a destination up to 2,048.

Redirecting a whole domain

To send every request for one domain to another, for example example.com to www.example.com, set a redirect on the domain instead of writing a rule: open the domain on the project's Domains tab, or run lahyer domains redirect example.com --to www.example.com. A domain's redirect applies to every path and goes before the rules in lahyer.json.

On this page