Route Matching Rules
The HTTP Gateway decides which backend resource receives a request based on two elements: domain and path. This article explains the matching order, the priority rules, and a set of examples you can compare against.
Matching elements
| Element | Matching | Notes |
|---|---|---|
| Domain | Exact match, wildcard * | Exact domains win over the wildcard; * matches any domain and is usually a fallback |
| Path | Prefix match | /bar matches /bar/xxx; within the same domain, the longest prefix wins |
Matching flow
The gateway resolves the domain first, then the path within that domain. Because paths use prefix matching, an exact path and a shorter prefix can coexist, and the longer one is selected.
Examples
Assume these six routes are configured:
| Domain | Path | Resource |
|---|---|---|
* | / | FunctionA |
* | /bar | FunctionB |
<default domain> | /bar | FunctionC |
foo.com | / | FunctionD |
foo.com | /bar | FunctionE |
foo.com | /bar/baz | FunctionF |
Requests resolve as follows:
| Request | Matched resource | Why |
|---|---|---|
<default domain>/xxx | FunctionA | No route for the default domain, so it falls back to *; path /xxx hits prefix / |
<default domain>/bar | FunctionC | The default domain matches exactly and wins over the wildcard; /bar matches exactly |
<default domain>/bar/xxx | FunctionC | The default domain matches exactly; /bar/xxx hits prefix /bar |
foo.com/xxx | FunctionD | foo.com matches exactly; /xxx hits prefix / |
foo.com/bar | FunctionE | foo.com matches exactly; /bar matches exactly |
foo.com/bar/xxx | FunctionE | foo.com matches exactly; /bar/xxx hits prefix /bar |
foo.com/bar/baz | FunctionF | foo.com matches exactly; /bar/baz matches exactly and beats /bar as the longest prefix |
Two rules cover most cases:
- Within a domain, the longer path wins:
/bar/bazbeats/bar, and/barbeats/ - For the same path, the exact domain wins: the
/barroutes onfoo.comand on the default domain do not conflict, and only when neither matches does the request fall back to*
Recommendations
- Use
*only as a fallback: an overly broad wildcard lets any domain use the path, so pair it with the security domain allowlist - Split by business prefix: for example,
/apito a cloud function and/staticto static hosting, instead of sending everything to one resource - Configure routes per custom domain: connecting a domain only makes it reachable; reaching a resource requires a matching route
Troubleshooting
When a request returns 404 or no response, check in this order:
- Whether the domain is connected: custom domain or wildcard domain
- Whether a route exists under that domain, and whether its path is a prefix of the request path
- Whether a longer prefix took the request, comparing against the examples above
- Whether the backend resource itself works. See the guide for your resource:
| Upstream resource | Guide |
|---|---|
| Cloud function | Access cloud functions over HTTP |
| Static hosting | Access static hosting over HTTP |
| CloudBase Run | Access CloudBase Run over HTTP |
| Cloud storage | Access cloud storage over HTTP |
Limits
Each domain supports up to 100 route rules. Submit a ticket if you need more.