Hi all,
I am stuck with trying to create a header rewrite rule for my application gateway. Unfortunately I am bound to certain policies so I only do this via Azure Devops and some Powershell or CLI scripts. Lucky for me the documentation provides a perfect example.
Also unfortunately I cannot seem to make it work even though everything seems to be configured correctly.
So I basically copied the script from the documentation and replace the regex expressions:
$responseHeaderConfiguration = New-AzApplicationGatewayRewriteRuleHeaderConfiguration -HeaderName "Location" -HeaderValue "https://gwhostname.com{http_resp_Location_2}"
$actionSet = New-AzApplicationGatewayRewriteRuleActionSet -ResponseHeaderConfiguration $responseHeaderConfiguration
$condition = New-AzApplicationGatewayRewriteRuleCondition -Variable "http_resp_Location" -Pattern "(http?):\/\/.*azurewebsites\.net(.*)$" -IgnoreCase
$rewriteRule = New-AzApplicationGatewayRewriteRule -Name LocationHeader -ActionSet $actionSet -Condition $condition
$rewriteRuleSet = New-AzApplicationGatewayRewriteRuleSet -Name LocationHeaderRewrite -RewriteRule $rewriteRule
$appgw = Get-AzApplicationGateway -Name $(GatewayName) -ResourceGroupName $(ResourceGroupName)
$reqRoutingRule = Get-AzApplicationGatewayRequestRoutingRule -Name $(GatewayRule) -ApplicationGateway $appgw
Add-AzApplicationGatewayRewriteRuleSet -ApplicationGateway $appgw -Name LocationHeaderRewrite -RewriteRule $rewriteRuleSet.RewriteRules
Set-AzApplicationGatewayRequestRoutingRule -ApplicationGateway $appgw -Name $(GatewayRule) -RuleType $reqRoutingRule.RuleType -HttpListenerId $reqRoutingRule.HttpListener.Id -RewriteRuleSetId $rewriteRuleSet.Id -UrlPathMapId $reqRoutingRule.UrlPathMap.Id
Set-AzApplicationGateway -ApplicationGateway $appgw
The commands were executed and I can see the configurations in the portal. However when verifying the Location header does not get rewritten. I even tried removing the condition, and providing an always true condition but a rewrite never happend.
Also in the Rewrites blade I see the Rules applied set to 1. However when going to the Update rewrite set blade, suddenly it doesn't seem to be associated to any routing rule (none of the boxes are checked). I noticed that when configuring everything manually in my own Azure portal the boxes of the latter are checked when applying the rewrite rule.
To me it seems that the Powershell script is missing something, but I am unable to debug any further. Does anyone faced this issue before? Or can help me find out how to make this work?