Azure API Management

Transform URL Policy

The set-url policy lets you rewrite the inbound request URL before it reaches the backend service. This is useful for scenarios such as versioning, routing, or proxying legacy endpoints.

Basic Syntax

<inbound>
    <rewrite-uri template="/v2/{path}" />
</inbound>

Full Example

<policies>
    <inbound>
        <base>
            <set-header name="X-Original-URL" exists-action="override">{{request-url}}</set-header>
        </base>
        <choose>
            <when condition="@(context.Request.MatchedParameters.ContainsKey("version") && context.Request.MatchedParameters["version"] == "v1")">
                <set-url template="/v1/{path}" />
            </when>
            <otherwise>
                <set-url template="/v2/{path}" />
            </otherwise>
        </choose>
    </inbound>
    <backend>
        <forward-request />
    </backend>
    <outbound>
        <base />
    </outbound>
</policies>

Interactive URL Transformer