I'm new to application gateway and wondering how to modify urls in application gateway and apim and send the original requests to backend service.
I have an application gateway set up with public ip which serves the internet requests.
And an api management service with a private endpoint (disable public network access). APIM with basic tier (can have only one custom domain) https://apim-test.com. APIM have two apis for staging and qa. Both these backend service have same endpoints examples:
staging: https://staging.xyz.com/api/v1/**
qa: https://qa.abc.com/api/v1/**
In the app gtw, both apis have different listeners set up. In the Rewrite rules, the path-based url are modified and are prefixed with /staging/api/*
and /qa/api/*
which are associated with apim backend pools.
In the apim, these requests are identified based on the string /staging or /qa and based on this are further sent to respective back-end service. Using apim policy I intend to remove the above prefix added to route and then send to the backend for further processing. With the rewrite-uri apim policy in place the gateway health probe starts to fail.
<inbound>
<base />
<choose>
<when condition="@(context.Request.OriginalUrl.Path.Contains("/staging"))">
<rewrite-uri template="@((context.Request.OriginalUrl.Path).Replace("/staging", ""))" />
<set-backend-service backend-id="staging-api-public-loadbalancer" />
<set-header name="Host" exists-action="override">
<value>staging.xyz.com</value>
</set-header>
</when>
</choose>
</inbound>
I'm wondering are the gateway rewrite rules and apim rewrite rule are correctly configured. Also when the requests are issued from browser, I get 404 requests doesn't exist. I tested without the prefix string in the request uris and I could reach the api endpoints.
app gtw rewrite rule
Health probe fails when rewrite rule added in the apim.
<rewrite-uri template="@((context.Request.OriginalUrl.Path).Replace("/staging", ""))" />
I had a wrong configuration when the requests were sent to backend. Enabling the Diagnostics settings in the APIM helped me to analyze the issue.
As well as the wrong pattern matching. The correct way to set rewrite-url is as follows.