Skip to main content

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​

ElementMatchingNotes
DomainExact match, wildcard *Exact domains win over the wildcard; * matches any domain and is usually a fallback
PathPrefix 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:

DomainPathResource
*/FunctionA
*/barFunctionB
<default domain>/barFunctionC
foo.com/FunctionD
foo.com/barFunctionE
foo.com/bar/bazFunctionF

Requests resolve as follows:

RequestMatched resourceWhy
<default domain>/xxxFunctionANo route for the default domain, so it falls back to *; path /xxx hits prefix /
<default domain>/barFunctionCThe default domain matches exactly and wins over the wildcard; /bar matches exactly
<default domain>/bar/xxxFunctionCThe default domain matches exactly; /bar/xxx hits prefix /bar
foo.com/xxxFunctionDfoo.com matches exactly; /xxx hits prefix /
foo.com/barFunctionEfoo.com matches exactly; /bar matches exactly
foo.com/bar/xxxFunctionEfoo.com matches exactly; /bar/xxx hits prefix /bar
foo.com/bar/bazFunctionFfoo.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/baz beats /bar, and /bar beats /
  • For the same path, the exact domain wins: the /bar routes on foo.com and 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, /api to a cloud function and /static to 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:

  1. Whether the domain is connected: custom domain or wildcard domain
  2. Whether a route exists under that domain, and whether its path is a prefix of the request path
  3. Whether a longer prefix took the request, comparing against the examples above
  4. Whether the backend resource itself works. See the guide for your resource:
Upstream resourceGuide
Cloud functionAccess cloud functions over HTTP
Static hostingAccess static hosting over HTTP
CloudBase RunAccess CloudBase Run over HTTP
Cloud storageAccess cloud storage over HTTP

Limits​

Each domain supports up to 100 route rules. Submit a ticket if you need more.