Skip to content
Help guide the future of agentgateway — Take the survey

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.
Page as Markdown

Return a redirect response that rewrites the scheme, host, path, or status code before a request reaches any backend.

Attaches to:

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.

SettingDescription
schemeReplaces 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.fullReplaces the host and the port.
authority.hostReplaces 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: autoKeeps 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: noneHas the same effect as leaving authority unset.
authority.portReplaces 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.fullReplaces the path and keeps the query string.
path.prefixReplaces 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.
statusSets the status code of the redirect response. Defaults to 302.

The following table shows the location header for a few redirect settings.

RequestRoute match and redirect settingslocation header
http://localhost:3000/old-host/a?x=1authority.host: example.comhttp://example.com:3000/old-host/a?x=1
http://localhost:3000/v1/users?x=1pathPrefix: /v1 match, path.prefix: /v2http://localhost:3000/v2/users?x=1
http://localhost:3000/secure/ascheme: httpshttps://localhost/secure/a
Was this page helpful?
Agentgateway assistant

Ask me anything about agentgateway configuration, features, or usage.

Note: AI-generated content might contain errors; please verify and test all returned information.

Tip: one topic per conversation gives the best results. Use the + button in the chat header to start a new conversation.

Switching topics? Starting a new conversation improves accuracy.
↑↓ navigate ↵ select esc dismiss

What could be improved?

Your feedback helps us improve assistant answers and identify docs gaps we should fix.

Need more help? Join us on Discord: https://discord.gg/y9efgEmppm

Want to use your own agent? Add the Solo MCP server to query our docs directly. Get started here: https://search.solo.io/.