similar rewrite-url not working for another routing rule

ahd 85 Reputation points
2025-01-20T23:10:59.4+00:00

I have a api management set up with basic tier which accepts one custom domain url. I have multiple api's defined ex: staging and qa both listening on the same url https://test.apim.com

The internet facing requests are as follows, staging https://qa.xyz.com/api/v1/get/products.. and qa https://staging.xyz.com/api/v1/get/products... Because apim with basic tier doesn't allow Multiple custom domain names for gateway, we are trying to modify the requests at gateway.

In the application gateway, I try to modify the incoming requests as shown below. Both environments have different backend pool, backend settings, routing rule and listeners set up. Based on this request uri prefix staging or qa the requests are routed to appropriate api in apim.

staging - original requests https://test.apim.com/api/v1/... modified as https://test.apim.com/staging/api/v1/...

qa - original requests https://test.apim.com/api/v1... modified as https://test.apim.com/qa/api/v1/...

Why does the rewrite rule is not applied in case of qa with lower priority ?

or Is there any other better way to achieve this in application gateway.

staging rewrite rule:User's image

qa rewrite-url: User's image

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,115 questions
{count} votes

Accepted answer
  1. Praveen Bandaru 235 Reputation points Microsoft Vendor
    2025-01-27T19:09:44.69+00:00

    Hello ahd

    Greetings!

    Thank you for your quick response.

    I'm glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this!

    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 solution.

    Please click "Accept" the answer as original posters help the community find answers faster by identifying the correct answer.

    Issue: similar rewrite-url not working for another routing rule

    Resolution: You resolved the issue by using the override backend path.

    Why Override Backend Path Works Well:

    The override backend path allows you to dynamically modify the request URL before it is forwarded to the backend. This can be particularly useful when you have multiple APIs and need to route requests based on specific patterns or domains.

    Here are some reasons why this approach might be beneficial:

    • Flexibility: The override backend path provides flexibility in routing requests. You can easily modify the path based on the incoming request, which is useful when dealing with multiple APIs.
    • Simplified Configuration: Using the override backend path can simplify the configuration compared to setting up multiple rewrite rules. This can make it easier to manage and maintain your application gateway settings.
    • Performance: By directly modifying the backend path, you can reduce the complexity of the routing rules, which can lead to better performance and faster request processing.

    I hope this has been helpful!

    Your feedback is important so please take a moment to accept answers. If you still have questions, please let us know what is needed in the comments so the question can be answered. Thank you for helping to improve Microsoft Q&A!

    Please accept an answer if correct. Original posters help the community find answers faster by identifying the correct answer. Here is how.

    Regards,

    Praveen


1 additional answer

Sort by: Most helpful
  1. Silvia Wibowo 5,126 Reputation points Microsoft Employee
    2025-01-22T04:08:06.3233333+00:00

    Hi @ahd , Azure Application Gateway has multiple configurations that can be used in combination, depending what your requirements are.

    • Application Gateway multi-site hosting (listener) - Multi-site hosting enables you to configure more than one web application on the same port of application gateways using public-facing listeners. You can also define wildcard host names in a multi-site listener and up to 5 host names per listener. To learn more, see wildcard host names in listener.
    • Request-routing rules - When you create an application gateway by using the Azure portal, you create a default rule. This rule binds the default listener with the default backend pool and the default backend HTTP settings. After you create the gateway, you can edit the settings of the default rule or create new rules. For more information, see Application Gateway request routing rules.
      • URL Path Based Routing - URL Path Based Routing allows you to route traffic to backend server pools based on URL Paths of the request. One of the scenarios is to route requests for different content types to different backend server pools.
      • Application Gateway redirect - You can use application gateway to redirect traffic. It has a generic redirection mechanism which allows for redirecting traffic received at one listener to another listener or to an external site.
      • Rewrite HTTP headers and URL - only available for the Application Gateway v2 SKU. Application Gateway allows you to rewrite selected content of requests and responses. With this feature, you can translate URLs, query string parameters and modify request and response headers. It also allows you to add conditions to ensure that the URL or the specified headers are rewritten only when certain conditions are met. These conditions are based on the request and response information.
    • HTTP Settings - include override back-end path and hostname. The application gateway routes traffic to the backend servers by using the configuration that you specify here. After you create an HTTP setting, you must associate it with one or more request-routing rules. For more information, see Application Gateway HTTP settings configuration.

    Regarding your question "should we allow any particular delay between consecutive editing to reflect the changes on the incoming requests?" - See the flowchart diagram here. The flow of traffic follows this order: listener, request-routing rules (including components inside it: URL path based routing, App Gateway redirect, Rewrite HTTP headers and URL), HTTP Settings.

    Changes in Rewrite HTTP headers and URL will impact the downflow HTTP Settings. You should plan your App Gateway configuration like the flowchart: from top (listener) to bottom (HTTP Settings).

    Please accept an answer if correct. Original posters help the community find answers faster by identifying the correct answer. Here is how.

    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.