Redirects
Send a domain, or some of its paths, to another URL without running an app.
A redirect answers visitors of a domain with a Location header, right at
the edge. It needs no app, no container and no build. Use one to move an old
domain to a new one, to send www to the apex, or to move a few paths
somewhere else.
A redirect belongs to a project and is served by the project's cluster. It owns its domains. A domain either redirects or routes to an app or site, never both.
Forward a domain
A forward sends every request on its domains to one URL. With
Keep path and Keep query on, https://old.example.com/pricing?plan=pro
goes to https://example.net/pricing?plan=pro. With both off, every request
goes to the target as written.
Path rules
For more control, a redirect holds an ordered list of rules instead of
a forward. Each rule has a match (when) and a target (then):
host: one of the redirect's domains. Leave it out to match all of them.path, one of:exact: this path only.prefix: this path and everything below it./docsmatches/docs/abut never/docsearch.glob::namematches one path segment, and a trailing*matches the rest.
to: the target URL. Its path and query can use${path}(the request path),${splat}(what*matched) and${name}(what:namematched).
Rules run top to bottom, and the first enabled rule that matches answers.
Put specific rules first and a catch-all (no path) last. For example, to
move a blog and send everything else to the home page:
/blog/*goes tohttps://example.net/guides/${splat}/- everything else goes to
https://example.net
Matching is case-sensitive. A request that no rule matches gets a 404.
Status codes
Pick Permanent (301) or Temporary (302). Browsers and search engines cache a permanent redirect, so start with temporary while you test.
GET and HEAD requests get the status you picked. Every other method gets
its method-keeping twin: 308 for permanent and 307 for temporary. A
POST to an API that moved therefore stays a POST.
Order at request time
When a request comes in, these steps run in this order:
- Redirects run first, at the edge.
- HTTP settings of the app or site, such as the
wwwredirect and HSTS. - A static site's own
_redirectsand_headersfiles.
A redirect therefore wins over a static site's _redirects.
Limits
| What | Limit |
|---|---|
| Rules per redirect | 20 |
| Redirects per project | 25 |
| Forwarded domains per organization | 250 |
| Target URL length | 2048 characters |
A target must be a public http or https URL. It may not point at a
private address or at the platform's own domains. Redirects that send
visitors round in a loop are refused when you save, and the error lists the
URLs of the loop.
Domains and DNS
Each domain of a redirect must be covered by a
verified domain of your
organization, just like an app domain. Point the domain at the project's
cluster with the same A/AAAA or CNAME records an
app domain uses. A certificate is then
issued automatically. Until it is issued, http:// already redirects, but
https:// shows a certificate error.
The project needs a cluster before it can hold a redirect.
Manage redirects
- Console: in the project designer, add a Redirect, choose its domains, then either forward them to a URL or add rules.
- Infrastructure as code: one file per redirect,
redirects/<name>.yaml. See Redirects in IaC.