Redirects
Verified : Automated tests passed for: Configuration files: The configuration files on this page were checked against their schema. End-to-end run: Every step ran in a fresh test environment and the results were checked.Return a redirect response that rewrites the scheme, host, path, or status code before a request reaches any backend.
Note
Agentgateway supports more than one configuration style. Where a feature can also be configured in the simplified llm or mcp modes, the examples on this page show each option in tabs. For more information, see Routing-based configuration.
Request redirectsRedirectA traffic management feature that sends clients to a different URL, with configurable scheme, authority, path, or status code. allow returning a direct response redirecting users to another location.
Start the path.full and path.prefix values with /. If you use path.prefix on a route that does not delegate to a route group, every match on the route must use pathPrefix. Agentgateway rejects a configuration that does not follow these rules.
For example, the following configuration will return a 307 Temporary Redirect response with the header location: https://example.com/new-path:
# yaml-language-server: $schema=https://agentgateway.dev/schema/config
mcp:
port: 3000
policies:
requestRedirect:
scheme: https
authority:
full: example.com
path:
full: /new-path
status: 307
targets:
- name: everything
stdio:
cmd: npx
args: ["@modelcontextprotocol/server-everything"]Each part of the redirect is optional. The redirect keeps every part of the request URL that you do not set.
| Setting | Description |
|---|---|
scheme | Replaces the scheme. If you set scheme to http or https without authority, the redirect drops the port of the request. The client then uses the default port of the new scheme. |
authority.full | Replaces the host and the port. |
authority.host | Replaces the host. The redirect keeps the port of the request, unless you also set scheme or the port is the default port of the scheme. |
authority: auto | Keeps the host and the port of the request, even when you also set scheme. For example, with scheme: https, a request to http://localhost:3000/a is redirected to https://localhost:3000/a. |
authority: none | Has the same effect as leaving authority unset. |
authority.port | Replaces the port. If the port is the default port of the scheme, such as 443 for https, the location header leaves out the port. |
path.full | Replaces the path and keeps the query string. |
path.prefix | Replaces the part of the path that the route’s pathPrefix match matched. The rest of the path and the query string stay the same. Use path.prefix only in a route where every match is a pathPrefix match. If a match of the route is an exact or regex match, the configuration fails to load with the error path prefix rewrite requires every match to be a path prefix match. |
status | Sets the status code of the redirect response. Defaults to 302. |
The following table shows the location header for a few redirect settings.
| Request | Route match and redirect settings | location header |
|---|---|---|
http://localhost:3000/old-host/a?x=1 | authority.host: example.com | http://example.com:3000/old-host/a?x=1 |
http://localhost:3000/v1/users?x=1 | pathPrefix: /v1 match, path.prefix: /v2 | http://localhost:3000/v2/users?x=1 |
http://localhost:3000/secure/a | scheme: https | https://localhost/secure/a |