Bagh, Saujol Welcome to the Microsoft Q&A Platform. Thank you for reaching out & I hope you are doing well. The following commands and document would come in handy,
- Set-AzApplicationGatewayUrlPathMapConfig
- Get-AzApplicationGatewayUrlPathMapConfig
- Create an application gateway with URL path-based redirection using Azure PowerShell
Please find the PS script below, for modifying the PathBasedRules of a Rule
$appgw = Get-AzApplicationGateway -ResourceGroupName <RGName> -Name <AppGwName>
$poolSettings = Get-AzApplicationGatewayBackendHttpSettings -ApplicationGateway $appgw -Name <HttpSettingsForThePathRule>
$defaultPool = Get-AzApplicationGatewayBackendAddressPool -ApplicationGateway
$appgw -Name <TheDefaultPool>
$pathBasedPool1 = Get-AzApplicationGatewayBackendAddressPool -ApplicationGateway $appgw -Name <ThePoolYouWantToAddForPath1>
$pathBasedPool2 = Get-AzApplicationGatewayBackendAddressPool -ApplicationGateway $appgw -Name <ThePoolYouWantToAddForPath2>
$PathRule1 = New-AzApplicationGatewayPathRuleConfig -Paths "/path1/*" -Name pathPathRule1 -BackendAddressPool $pathBasedPool -BackendHttpSettings $poolSettings
$PathRule2 = New-AzApplicationGatewayPathRuleConfig -Paths "/path2/*" -Name pathPathRule2 -BackendAddressPool $pathBasedPool -BackendHttpSettings $poolSettings
$appgw = Set-AzApplicationGatewayUrlPathMapConfig -ApplicationGateway $appgw -Name <NameOfTheRuleinAppGw> -PathRules $PathRule1, $PathRule2 -DefaultBackendAddressPoolId $defaultPool.Id -DefaultBackendHttpSettingsId $poolSettings.Id
Set-AzApplicationGateway -ApplicationGateway $appgw
The above is a generic one. In your case, you can use one PathRule and get this done. So, your commands become,
$PathRule1 = New-AzApplicationGatewayPathRuleConfig -Paths "/test*" -Name pathPathRule1 -BackendAddressPool $pathBasedPool -BackendHttpSettings $poolSettings
and
$appgw = Set-AzApplicationGatewayUrlPathMapConfig -ApplicationGateway $appgw -Name <NameOfTheRuleinAppGw> -PathRules $PathRule1 -DefaultBackendAddressPoolId $defaultPool.Id -DefaultBackendHttpSettingsId $poolSettings.Id
Hope this helps. Thanks, Kapil
Please don’t forget to close the thread by clicking "Accept the answer" wherever the information provided helps you, as this can be beneficial to other community members.