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, and404,410,451(answer with the page named by the destination). :namematches 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
200rewrite 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=andCookie=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.
, . 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
- Rules, in order:
app.yamlroutes, then_redirects. The first rule that matches wins. A rule that is not forced (!orforce: true) is skipped when a file exists at the requested path, so a stray rule cannot hide real content. - Files: the exact file, then
path.htmlwhen clean URLs are on, thenpath/index.html. Trailing slash and clean URL redirects happen here. - Single page app fallback, when
static.spais on: a path with no file and no extension servesindex.htmlwith status 200. A missing/app.jsstill returns 404. - 404 page, served with status 404. If there is none, a plain 404 response.
Proxy a path to another app
A rule whose target isapp://<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.
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.
fromtakes literal segments and an optional trailing*.:splatin the target is replaced by what*matched./api/*withapp://my-api/v1/:splatsends/api/users/7to/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: proxyandtarget_state(ok,missingorself), 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-Cookiefrom the target is removed, andX-Content-Type-Options: nosniffis added. ALocationheader that names the target’s internal address is made relative. - At most
APP_PAGES_PROXY_MAX_RULESproxy rules per site. A proxy route caps the request body at thepages.proxy_max_body_mbruntime setting (default 10 MiB, seeded byAPP_PAGES_PROXY_MAX_BODY_MB) and waits at most thepages.proxy_response_timeoutruntime setting (default 30s, seeded byAPP_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}. TheCookieheader is never forwarded, and when the site has a password gate theAuthorizationheader 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
httporhttpsURL. 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
Locationheader. - 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.jsorindex-9f8e7d6c.css, or hashed bundles under/assets/,/_astro/,/_next/static/and/static/) are sent asCache-Control: public, max-age=<N>, immutable.Ncomes fromAPP_STATIC_ASSET_MAX_AGE(seconds, default 31536000). - Everything else (HTML, JSON manifests,
sw.js,service-worker.js) is sent asCache-Control: no-cache, so browsers revalidate with the ETag. - A
Cache-Controlset or removed in_headersorapp.yamlalways wins. - Text responses (HTML, CSS, JavaScript, JSON, SVG) are compressed with zstd or gzip when at least
APP_STATIC_COMPRESS_MIN_LENGTHbytes (default 256). Images, fonts, video and archives are sent as they are.