Redirects
Declare a project's redirects in redirects/<name>.yaml, as a forward or as ordered path rules.
A project link declares each redirect in its own
file, projects/<project>/redirects/<name>.yaml. The file name is the
redirect's name: lowercase letters, digits and -, at most 63 characters.
Forward a domain
Send old.example.com to https://example.net, keeping the path and the
query:
# yaml-language-server: $schema=https://a-line.cloud/schemas/iac/v1.json
version: 1
domains:
- domain: old.example.com
- domain: www.old.example.com
forward:
to: https://example.net
status: 301
keep_path: true
keep_query: truehttps://old.example.com/pricing?plan=pro then answers 301 with
Location: https://example.net/pricing?plan=pro.
Path rules
Rules run top to bottom, and the first match answers. Here /blog/* moves
to the guides, and the catch-all after it sends everything else to the home
page:
# yaml-language-server: $schema=https://a-line.cloud/schemas/iac/v1.json
version: 1
domains:
- domain: docs.example.com
rules:
- name: blog
when:
path:
glob: /blog/*
then:
redirect:
to: "https://example.net/guides/${splat}/"
status: 301
keep_query: true
- name: everything-else
then:
redirect:
to: https://example.net
status: 302
keep_query: falsehttps://docs.example.com/blog/launch goes to
https://example.net/guides/launch/. Put the catch-all last: a rule with no
when matches every request, so any rule below it never runs.
Quote a to that uses ${...} placeholders, as above.
Keys
| Key | Meaning |
|---|---|
domains | The hosts the redirect answers, at least one. Each is an exact host covered by a verified (or still verifying) domain granted to the link. |
forward | Send every request to to. Needs status (301 or 302), keep_path and keep_query. |
rules | Ordered rules, at most 20. Use either forward or rules, not both. |
enabled | false keeps the redirect but stops it answering. Defaults to true. |
allow_delete | Let removing the file delete the redirect, see removing. |
A rule has these keys:
| Key | Meaning |
|---|---|
name | A label shown in the console. |
enabled | false keeps the rule but skips it. Defaults to true. |
when.host | One of the redirect's domains. Leave it out to match all of them. |
when.path | One of exact: /a, prefix: /a (also matches /a/b, never /ab) or glob: /a/:id/*. Leave it out to match every path. |
then.redirect.to | The target URL. Its path and query can use ${path}, ${splat} and the glob's ${name} captures. |
then.redirect.status | 301 (permanent) or 302 (temporary). Methods other than GET and HEAD get 308 or 307. |
then.redirect.keep_query | Append the request's query to the target. |
Checks
iac-check and the sync refuse a redirect file when:
- a domain is not covered by a verified domain granted to the link;
- a domain is also listed in another redirect file, or in the
domainsof an app or site of the project (a domain either redirects or routes); - another app or redirect already serves the domain;
- the target is not a public
httporhttpsURL; - the redirects send visitors round in a loop;
- a limit is reached.
An uncovered domain fails the whole sync, because a redirect has no other use for it. The project also needs a cluster.
Removing a file
A redirect a file manages is read-only in the console and the API. Removing
the file releases the redirect: it keeps answering, and you manage it in the
console from then on. To delete it with the file, first sync the file
with allow_delete: true, then remove it. The redirect and its domains are
deleted on the next sync. A redirect holds no data, so the deletion is not
held for approval.
In the console
- Open the project and choose Redirect in the designer's sidebar.
- Pick a template, such as Forward a domain, and enter its domains.
- Enter the target URL, choose Permanent (301) or Temporary (302), and turn Keep path and Keep query on or off.
- For path rules, open Advanced and add rules in the order they should run.
Export writes each redirect back as redirects/<name>.yaml, using the
forward form for a forward. Defaults (enabled: true) are left out.