APIM gateway url is redirecting in browser to wrong backend url, but not with curl and in API Designer Test

kiecodes 10 Reputation points
2024-01-31T09:21:33.1833333+00:00

Hello,
I encountered the following behaviour.

I have a test-setup running here:
https://fnappmiqnetek5loc4.azure-api.net/

Running curl https://fnappmiqnetek5loc4.azure-api.net/ returns the correct result. As well as running this in the APIM -> API -> Get Root -> Test view.

But opening this in the browser redirects the browser url to: https://fnappmiqnetek5loc4.azure-api.net/get_root Which is wrong.

Here is my setup:

Policies

<policies>
    <inbound>
        <base />
        <set-backend-service backend-id="functionsapp-backend" />
        <rewrite-uri template="/get_root" />
    </inbound>
    <backend>
        <base />
    </backend>
    <outbound>
        <base />
    </outbound>
    <on-error>
        <base />
    </on-error>
</policies>

API User's image

Backend User's image

Please let me know if there is any other information you need to understand the issue. Any help would be appreciated.

Thank you!

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

2 answers

Sort by: Most helpful
  1. Deepanshukatara-6769 16,565 Reputation points Moderator
    2024-01-31T11:18:08.0033333+00:00

    Hi , If you want to remove the rewrite behavior and keep the original URL intact, you should remove or modify that line. Here's an updated version of your policies without the URI rewrite:

    <policies>
        <inbound>
            <base />
            <set-backend-service backend-id="functionsapp-backend" />
            <!-- Remove the rewrite-uri line to keep the original URL -->
        </inbound>
        <backend>
            <base />
        </backend>
        <outbound>
            <base />
        </outbound>
        <on-error>
            <base />
        </on-error>
    </policies>
    
    
    

  2. MuthuKumaranMurugaachari-MSFT 22,441 Reputation points Moderator
    2024-01-31T17:26:52.24+00:00

    kiecodes Thanks for your engagement in the community and glad to hear that your issue was resolved. Since the Microsoft Q&A community has a policy that the question author cannot accept their own answer, they can only accept answers by others, I'll repost your own solution in case you'd like to Accept the answer.

    Resolution:

    The issue appeared to be a caching issue and it worked as expected later.

    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.