Skip to main content

What this covers

A static site (build.type: static, see Static pages) can carry its own routing rules in the repository. They are read at deploy time, compiled, and published together with the files, so a rollback restores the rules that went with that version of the site. This page covers the _redirects and _headers files, the matching app.yaml fields, the serving options, the order rules are evaluated in, and how to test them.

Where rules come from

The two files are removed from the served tree when the deploy is published, so visitors cannot download them. Rules from app.yaml rank before rules from _redirects.

_redirects

One rule per line: from [query matches] to [status[!]]. Lines starting with # are comments.
  • The default status is 301. Supported statuses: 200 (rewrite), 301, 302, 303, 307, 308, and 404, 410, 451 (answer with the page named by the destination).
  • :name matches one path segment and * matches the rest of the path (last segment only). Both can be used in the destination. * is available as :splat.
  • Matching ignores case and a trailing slash.
  • The visitor’s query string is passed on to a redirect destination that has no query of its own.
  • A 200 rewrite must point at a path on this site. Rewriting to another site (a proxy) is not supported; use a path forwarder on the domain instead.
  • Conditions such as Country=, Language=, Role= and Cookie= need an edge runtime and are not supported. A line that uses one is skipped and reported.

_headers

A path line, then indented header lines. Use ! Name to remove a header.
Every block whose path matches the request applies. If the same header is set more than once, the values are joined with , . Headers the ingress manages (Host, Content-Length, Connection, Transfer-Encoding, X-Forwarded-* and a few others) cannot be set. Header names must be valid tokens and values must be a single line.

app.yaml

These fields are only valid with build.type: static. A mistake in them fails the deploy before anything is published.

Order of evaluation

  1. Rules, in order: app.yaml routes, then _redirects. The first rule that matches wins. A rule that is not forced (! or force: true) is skipped when a file exists at the requested path, so a stray rule cannot hide real content.
  2. Files: the exact file, then path.html when clean URLs are on, then path/index.html. Trailing slash and clean URL redirects happen here.
  3. Single page app fallback, when static.spa is on: a path with no file and no extension serves index.html with status 200. A missing /app.js still returns 404.
  4. 404 page, served with status 404. If there is none, a plain 404 response.
A redirect that would send a request to the path it came from is skipped rather than looping.

Proxy a path to another app

A rule whose target is app://<name>/<path> with status 200 forwards matching requests to another app on the same Levelrail. The browser sees one origin, so the page needs no CORS setup.
The same rule can be added in the dashboard rules or with pages routes add my-site '/api/*' 'app://my-api/:splat' (status defaults to 200 for an app:// target). How it behaves:
  • The target is an app name on this Levelrail, never a URL. The control plane resolves it to the app’s internal address, so a rule cannot reach an arbitrary host.
  • from takes literal segments and an optional trailing *. :splat in the target is replaced by what * matched. /api/* with app://my-api/v1/:splat sends /api/users/7 to /v1/users/7. The query string is carried over.
  • All methods are forwarded and request and response bodies stream. Hop by hop headers are dropped, and X-Forwarded-* headers are set by the proxy, never taken from the client.
  • A proxy rule applies even when a file exists at the path, so keep it to paths that are not files. The site password gate, when set, is checked first.
  • Request paths with . or .. segments get a 400. A captured path holding a space, ?, # or a non ASCII character does not match the rule and falls through to the files.
  • Proxy rules are served on the live site only. Per-deploy hosts and pull request previews serve files only.
  • When the target app does not exist, is not running, or is the site itself, the path answers 502 with a fixed message. The routing rules API marks the rule with kind: proxy and target_state (ok, missing or self), and the site checks card lists a proxy target that is not reachable.
  • Writing a dashboard rule needs read access to the target app. A rule for an app you cannot read, or one that does not exist, is refused with the same message. A rule that is the site itself is refused.
  • Who may name a target: a deploy that carries proxy rules is checked against the target app the same way as the dashboard rules, so the acting principal needs deploy access to it. A target behind an access gate (auth gate or basic auth on any of its domains), with a geo, shield (rate limit) or forwarder policy on any domain, or in a protected environment is refused with the same message as a missing one. The controller applies the same check on every pass, so a target that gains one of these later answers 502, and so does a rollback to an older tree. A target that does not exist and one you cannot read fail with the same message, which names the target. A manual or upload deploy, including source_url, acts as the caller. A git push, hook, replay or queued deploy has no interactive caller, so the target must be in the site’s own team and project, pass the same checks, and already be served by the site’s live rules. A new target is refused with the same message plus a hint to deploy from the dashboard or CLI, where you approve it. An app with no domain is internal only: you need deploy access to it, and only an interactive deploy can add it. Pull request previews drop proxy rules and say so in the deploy log.
  • The target’s team and project are recorded at deploy. If the app is later moved elsewhere the path answers 502 until the site is redeployed. A site deployed before this record keeps serving until its next deploy.
  • Proxy responses never set cookies on the site origin: Set-Cookie from the target is removed, and X-Content-Type-Options: nosniff is added. A Location header that names the target’s internal address is made relative.
  • At most APP_PAGES_PROXY_MAX_RULES proxy rules per site. A proxy route caps the request body at the pages.proxy_max_body_mb runtime setting (default 10 MiB, seeded by APP_PAGES_PROXY_MAX_BODY_MB) and waits at most the pages.proxy_response_timeout runtime setting (default 30s, seeded by APP_PAGES_PROXY_RESPONSE_TIMEOUT) for the target to start answering, then returns 502. WebSocket upgrades stay allowed. Both apply at the next ingress refresh.
  • Rule paths and targets must not contain { or }. The Cookie header is never forwarded, and when the site has a password gate the Authorization header is dropped too.
  • The controller re-checks each target’s team and project on every pass. A proxy with no recorded scope (rules written before scopes existed) answers 502 until the site is redeployed. Saving settings or rules never widens a recorded scope: a target that moved teams loses its scope and answers 502 until a real deploy, and a scope is only added for a target the saving request was just authorized for.

Safety

  • Redirect destinations are either a path on this site or an absolute http or https URL. A destination that starts with //, contains backslashes or whitespace, carries credentials, or uses a placeholder in its host is rejected, so a rule cannot become an open redirect.
  • Values captured from the request are re-escaped before they are placed in a Location header.
  • Header names and values are checked for control characters, so a rule cannot inject a second header.
  • Matching uses linear time regular expressions, so a crafted URL cannot stall the ingress.

Limits

Going over a cap fails the deploy with the variable’s name in the message.

Problems and the deploy log

A bad line in _redirects or _headers is skipped, never applied half understood, and reported in the deploy log under Compile routing rules with its file and line number. The same problems are listed on the Routing rules page of the app. The previous deploy keeps serving until the new one is published, and a failed deploy leaves its rules untouched.

See the rules and test a URL

The Routing rules page of a static app (Traffic section of the app menu) shows the parsed rules, header blocks, options and any problems. Test a URL runs a path through the live rules and files and shows which rule or file answered, the status, and each step considered. Check rules before deploying parses pasted _redirects or _headers text without deploying. The same from the CLI and the API:
lint exits non-zero when the text has problems, so it fits a CI step.

Default caching and compression

Static sites get these defaults when your rules set nothing for the path.
  • Fingerprinted assets (a content hash in the file name such as app.abc123def.js or index-9f8e7d6c.css, or hashed bundles under /assets/, /_astro/, /_next/static/ and /static/) are sent as Cache-Control: public, max-age=<N>, immutable. N comes from APP_STATIC_ASSET_MAX_AGE (seconds, default 31536000).
  • Everything else (HTML, JSON manifests, sw.js, service-worker.js) is sent as Cache-Control: no-cache, so browsers revalidate with the ETag.
  • A Cache-Control set or removed in _headers or app.yaml always wins.
  • Text responses (HTML, CSS, JavaScript, JSON, SVG) are compressed with zstd or gzip when at least APP_STATIC_COMPRESS_MIN_LENGTH bytes (default 256). Images, fonts, video and archives are sent as they are.

Rollback

Rules are stored beside the published files of each deploy. Rolling back to an earlier deploy (see Rollback) serves that deploy’s files and its rules together. Sites published before routing rules existed have none; deploy them once to enable the options.
Last modified on November 20, 2026