azure app gateway rewrite rules not able to reroute to with a regular expression

Gaurav Kumar 20 Reputation points
2024-06-11T14:26:01.0433333+00:00

we have incoming url pattern in our organisation as

api.domain1.com/{partnername}/{api_name}/{opearation_name}

now we want to setup rewrite rule so that anything coming the in above url with "partnername" gets replaces with "webservicecore",

so we use this regular expression "/([^/])/(.)$"

now when we check in log analytics the request url is correctly replaced with "webservicecore" but gateway does not sends traffic to backend APIM.

we have setup path based routing with reroute = true in rewrite rules config.

app gateway throws 502 error.

Azure Application Gateway
Azure Application Gateway
An Azure service that provides a platform-managed, scalable, and highly available application delivery controller as a service.
1,012 questions
{count} votes

Accepted answer
  1. UJTyagi-MSFT 310 Reputation points Microsoft Employee
    2024-06-12T09:35:44.8566667+00:00

    Hi @Gaurav Kumar

    Welcome to the Microsoft Q&A Platform. Thank you for reaching out & I hope you are doing well.

    Thanks for posting your query. There is one important setting in the Rewrite configuration - "Re-evaluate path map". Kindly note if this setting is unselected the original URL path will be used to match the path-pattern in the URL path map. In your case path-pattern will be matched against api.domain1.com/{partnername}/ and post Rewrite **api.domain1.com/**webservicecore will be sent to same backend as selected for partnername.

    However, if Reevaluate setting is selected there will be again path lookup through the path map after Rewrite which means after Rewrite again path lookup will be performed for **api.domain1.com/**webservicecore and if there is a different path available for **/**webservicecore that will be selected. This is important setting which is overlooked sometimes and cause the problem.

    This is also a common pitfall associated if you apply with the basic routing rule. Kindly you may go through the below link -

    https://learn.microsoft.com/en-us/azure/application-gateway/rewrite-http-headers-url#rewrite-configuration-common-pitfalls

    User's image

    Regards

    Ujjawal


0 additional answers

Sort by: Most helpful