<redirect-content-urls /> produces invalid URL when used with <rewrite-uri />

Raimondas Rimkus 1 Reputation point
2020-11-05T07:27:54.123+00:00

Goal: response body contains full backend server URL that needs to be replaced with API management server URL. API URL and Operation URLs can't be changed. Operation contains rewrite-uri policy to map API Management URL to root backend URL.

API management URL (obfuscated): https://my.api.management.com/
API URL: redirect-test
Operation URL: /this/part/is/not/found

Policy:

    <policies>
        <inbound>
            <base />
            <rewrite-uri template="/" />
            <set-backend-service base-url="https://petstore.swagger.io/" />
        </inbound>
        <backend>
            <base />
        </backend>
        <outbound>
            <base />
            <redirect-content-urls />
        </outbound>
        <on-error>
            <base />
        </on-error>
    </policies>

Request: https://my.api.management.com/redirect-test/this/part/is/not/found
Backend response contains: url: "https://petstore.swagger.io/v2/swagger.json"
API Management response contains: url: "https://my.api.management.com/redirect-test/v2/swagger.json"
Expected API Management response: url: "https://my.api.management.com/redirect-test/this/part/is/not/found/v2/swagger.json",

Content is properly replaced (operation URL included) if rewrite-uri is not used.

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
2,117 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. ChaitanyaNaykodi-MSFT 26,101 Reputation points Microsoft Employee
    2020-11-07T01:29:59.667+00:00

    Hello @Raimondas Rimkus , based on this solution here. <rewrite-uri template="/" /> will override the operation URL and https://my.api.management.com/redirect-test/ will be mapped to https://petstore.swagger.io/. Now if you do not do rewrite-uri then https://my.api.management.com/redirect-test/this/part/is/not/found will be mapped to https://petstore.swagger.io/this/part/is/not/found. Now regarding the <redirect-content-urls /> will just replace the backend URI with APIM URI. Can you please confirm if you want to map https://my.api.management.com/redirect-test/ to https://petstore.swagger.io/ ?

    0 comments No comments

  2. Raimondas Rimkus 1 Reputation point
    2020-11-16T07:58:12.06+00:00

    We need to use rewrite-uri to reformat the URL to the backend format, and we need to use redirect-content-urls to mask all the backend URLs in the response body. As described in the first post, we need to map https://my.api.management.com/redirect-test/this/part/is/not/found/ to https://petstore.swagger.io/ in the inbound operation (where /redirect-test/ is API URL and this/part/is/not/found/ is operation URL) and map it back in the outbound operation.

    They both work properly when not used together, but we need to use both policies in a single operation.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.