> For the complete documentation index, see [llms.txt](https://docs.serverlessapigateway.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.serverlessapigateway.com/reader-guides/routing-exact-vs-parameter-vs-wildcard/routing-path-priority-explained.md).

# Routing: Match Priority Explained

Understand why exact matches beat parameterized routes and why parameterized routes beat wildcard routes. The gateway evaluates all defined paths against the incoming request and selects the most specific match. This page explains the priority algorithm so you can predict which route handles any given request.

**Last reviewed:** 2026-03-06

## When to use this

Use the routing guides when you need to understand how the gateway matches incoming requests to configured paths. Routing is the core behavior of the gateway -- every request passes through the path matcher before reaching an integration, auth check, or static response.

## Key concepts

* The gateway supports three route shapes: exact paths (`/health`), parameterized paths (`/users/:id`), and wildcard paths (`/proxy/{.+}`). Exact matches take highest priority.
* When multiple routes could match a request, the gateway uses a fixed priority order: exact > parameterized > wildcard. This is not configurable.
* The `method` field accepts standard HTTP methods (`GET`, `POST`, etc.) as well as `ANY`, which matches all methods on that path.
* Prefix add/remove rules transform the path before forwarding to the upstream, letting you decouple public API structure from backend path layout.
* Static response routes skip integration entirely and return the `response` field directly, which is useful for health checks and feature flags.

## Repo-grounded example

```json
{
  "servers": [
    { "alias": "upstream", "url": "https://api.example.com/base" }
  ],
  "paths": [
    {
      "method": "GET",
      "path": "/proxy/{.+}",
      "integration": {
        "type": "http_proxy",
        "server": "upstream"
      }
    }
  ]
}
```

This snippet defines a wildcard route, which has the lowest priority. If you add an exact path like `"/proxy/health"` in a separate entry, it will always match before this wildcard, regardless of definition order in the config.

## Troubleshooting

* If a request hits the wrong route, check whether a wildcard pattern is matching before your intended exact or parameterized route -- exact always wins over wildcard.
* If an OPTIONS request returns unexpected results, verify whether you have an explicit OPTIONS handler for that path or are relying on the default CORS 204 behavior.
* If prefix removal produces a double-slash in the upstream URL, confirm that both the `remove_prefix` and the upstream `url` do not include trailing/leading slashes that conflict.
* Use `wrangler tail` and look at the matched path in the log output to confirm which route config entry the gateway selected.

## Related docs

* [README](/configuration/paths.md)
* [add and remove prefix](/configuration/add-and-remove-prefix.md)
* [gateway troubleshooting matrix](/troubleshooting/wrangler-deploy-guide/gateway-troubleshooting-matrix.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.serverlessapigateway.com/reader-guides/routing-exact-vs-parameter-vs-wildcard/routing-path-priority-explained.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
