Search code examples
azurehttp-redirectazure-application-gatewayazure-front-door

Azure FrontDoor Premium, using rule engine to rewrite HTTP response based on returned 301


I am currently migrating an environment from Azure Application Gateway V2 with WAF to Azure FrontDoor Premium. I had to address an application behavior in the Application Gateway Rule Engine. Unfortunately, the application has a bug that cannot be fixed, so as a workaround, I am currently rewriting the HTTP location redirect.

[Configuration in AGW](https://i.sstatic.net/wdfvM.png)

When attempting to recreate the rule on Azure FrontDoor Premium, I found that the action within the rule configuration allows me to modify a response. However, I am missing a condition to react and modify the response based on a returned location header within the HTTP response.

Rule conditions in Azure FrontDoor(https://i.sstatic.net/vtbKx.png)

So far, I have not been able to find a way to react and modify the redirects. Additionally, I do not want to modify all the responses from my application because most of the returned location headers are correct.

Is it possible to create a condition and then rewrite the HTTP response in this manner with Azure FrontDoor Premium?


Solution

  • Is it possible to create a condition and then rewrite the HTTP response in this manner with Azure Front Door Premium?

    In AFD it's not possible. Azure Front Door rules engine does not support rewriting the location response header like Application gateway does, where it can save the original values in variables and use them for the rewrite. Azure Front Door only allows you to rewrite it for a specific value and also there can't be a match condition based on response header.

    enter image description here

    The MsDoc states that it doesn't have a way in Front Door to rewrite the location response header to fix the 301 responses. We can only append, overwrite, or delete specific response headers in the AFD rules engine.

    enter image description here

    • To make this work, you need to use some other parameter about the request that would provoke the redirect and location header, and then do the rewrite based of that.

    • If you can anticipate the conditions that would cause the origin to redirect to itself, you can create request header/url path/whatever conditions for that and do the location response header rewrites. You have to fix the origin so that it generates redirects to the correct location, and not back to itself.

    You can use Application gateway, this architecture is to preserve the original HTTP hostname. Rewriting host headers or location headers is not recommended usually.

    Reference:

    Host name preservation - Azure Architecture Center | Microsoft Learn