Skip to content

Commit abecfb5

Browse files
Merge pull request #302784 from MicrosoftDocs/main
Auto Publish – main to live - 2025-07-15 22:00 UTC
2 parents 550a6c4 + e276614 commit abecfb5

File tree

48 files changed

+710
-450
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+710
-450
lines changed

articles/application-gateway/add-http-header-rewrite-rule-powershell.md

Lines changed: 66 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,51 +5,68 @@ services: application-gateway
55
author: mbender-ms
66
ms.service: azure-application-gateway
77
ms.topic: how-to
8-
ms.date: 04/12/2019
8+
ms.date: 07/09/2025
99
ms.author: mbender
1010
ms.custom: devx-track-azurepowershell
1111
# Customer intent: "As a cloud administrator, I want to configure HTTP header rewrites using Azure PowerShell, so that I can efficiently modify headers in requests and responses for my Application Gateway."
1212
---
1313
# Rewrite HTTP request and response headers with Azure Application Gateway - Azure PowerShell
1414

15-
This article describes how to use Azure PowerShell to configure an [Application Gateway v2 SKU](./application-gateway-autoscaling-zone-redundant.md) instance to rewrite the HTTP headers in requests and responses.
15+
This article describes how to use Azure PowerShell to configure an [Application Gateway v2 SKU](./application-gateway-autoscaling-zone-redundant.md) instance to rewrite HTTP headers in requests and responses. Header rewriting enables you to add, remove, or update HTTP headers while the request and response packets move between the client and backend pools.
1616

1717
If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin.
1818

19-
## Before you begin
19+
## Prerequisites
2020

21-
- You need to run Azure PowerShell locally to complete the steps in this article. You also need to have Az module version 1.0.0 or later installed. Run `Import-Module Az` and then `Get-Module Az` to determine the version that you have installed. If you need to upgrade, see [Install Azure PowerShell module](/powershell/azure/install-azure-powershell). After you verify the PowerShell version, run `Login-AzAccount` to create a connection with Azure.
22-
- You need to have an Application Gateway v2 SKU instance. Rewriting headers isn't supported in the v1 SKU. If you don't have the v2 SKU, create an [Application Gateway v2 SKU](./tutorial-autoscale-ps.md) instance before you begin.
21+
Before you begin, ensure you have the following requirements:
2322

24-
## Create required objects
23+
- **Azure PowerShell**: You need Azure PowerShell installed locally or access to Azure Cloud Shell. The Azure PowerShell Az module version 1.0.0 or later is required. To check your version, run `Get-Module -ListAvailable Az`. If you need to upgrade, see [Install Azure PowerShell module](/powershell/azure/install-azure-powershell).
24+
- **Azure connection**: After verifying the PowerShell version, run `Connect-AzAccount` to authenticate with Azure.
25+
- **Application Gateway v2**: You need an existing Application Gateway v2 SKU instance. Header rewriting is only supported in the v2 SKU (Standard_v2 or WAF_v2). If you don't have one, create an [Application Gateway v2 SKU](./tutorial-autoscale-ps.md) instance before you begin.
26+
- **Proper permissions**: Ensure you have Contributor or Owner permissions on the Application Gateway resource.
2527

26-
To configure HTTP header rewrite, you need to complete these steps.
28+
> [!IMPORTANT]
29+
> Header rewrite functionality is only available with Application Gateway v2 SKU. The v1 SKU doesn't support this feature.
2730
28-
1. Create the objects that are required for HTTP header rewrite:
31+
## Understanding HTTP header rewrite components
2932

30-
- **RequestHeaderConfiguration**: Used to specify the request header fields that you intend to rewrite and the new value for the headers.
33+
To configure HTTP header rewrite, you need to understand and create the following components in a specific order:
3134

32-
- **ResponseHeaderConfiguration**: Used to specify the response header fields that you intend to rewrite and the new value for the headers.
35+
### Core components
3336

34-
- **ActionSet**: Contains the configurations of the request and response headers specified previously.
37+
1. **RequestHeaderConfiguration**: Specifies the request header fields you want to rewrite and their new values. Use this component to modify headers in client requests before they reach the backend servers.
3538

36-
- **Condition**: An optional configuration. Rewrite conditions evaluate the content of HTTP(S) requests and responses. The rewrite action will occur if the HTTP(S) request or response matches the rewrite condition.
39+
2. **ResponseHeaderConfiguration**: Specifies the response header fields you want to rewrite and their new values. Use this component to modify headers in server responses before they reach the client.
3740

38-
If you associate more than one condition with an action, the action occurs only when all the conditions are met. In other words, the operation is a logical AND operation.
41+
3. **ActionSet**: Contains the configurations of the request and response headers specified. Each action set represents a collection of header modifications to perform.
42+
43+
- **Condition**: An optional configuration. Rewrite conditions evaluate the content of HTTP(S) requests and responses. The rewrite action occurs if the HTTP(S) request or response matches the rewrite condition.
3944

40-
- **RewriteRule**: Contains multiple rewrite action / rewrite condition combinations.
45+
> [!NOTE]
46+
> Multiple conditions associated with an action use logical AND operation - all conditions must be met for the action to execute.
4147
42-
- **RuleSequence**: An optional configuration that helps determine the order in which rewrite rules execute. This configuration is helpful when you have multiple rewrite rules in a rewrite set. A rewrite rule that has a lower rule sequence value runs first. If you assign the same rule sequence value to two rewrite rules, the order of execution is non-deterministic.
48+
5. **RewriteRule**: Combines multiple rewrite actions and rewrite conditions. Each rule defines when and how to modify headers.
4349

44-
If you don't specify the RuleSequence explicitly, a default value of 100 is set.
50+
6. **RuleSequence** (Optional): Determines the execution order when you have multiple rewrite rules in a rewrite set. Rules with lower sequence values execute first. If you don't specify a value, the default is 100.
4551

46-
- **RewriteRuleSet**: Contains multiple rewrite rules that will be associated to a request routing rule.
52+
> [!WARNING]
53+
> If you assign the same sequence value to multiple rules, the execution order becomes non-deterministic.
4754
48-
2. Attach the RewriteRuleSet to a routing rule. The rewrite configuration is attached to the source listener via the routing rule. When you use a basic routing rule, the header rewrite configuration is associated with a source listener and is a global header rewrite. When you use a path-based routing rule, the header rewrite configuration is defined on the URL path map. In that case, it applies only to the specific path area of a site.
55+
7. **RewriteRuleSet**: Contains multiple rewritten rules that are associated with a request routing rule.
4956

50-
You can create multiple HTTP header rewrite sets and apply each rewrite set to multiple listeners. But you can apply only one rewrite set to a specific listener.
57+
### Application scope
5158

52-
## Sign in to Azure
59+
The rewrite configuration scope depends on the routing rule type:
60+
61+
- **Basic routing rule**: Header rewrite configuration applies globally to all requests for the associated listener
62+
- **Path-based routing rule**: Header rewrite configuration applies only to requests matching specific URL path patterns defined in the URL path map
63+
64+
> [!IMPORTANT]
65+
> You can create multiple HTTP header rewrite sets and apply each set to multiple listeners, but only one rewrite set can be applied to a specific listener.
66+
67+
## Authenticate with Azure
68+
69+
Before configuring header rewrite rules, authenticate with Azure and select your subscription:
5370

5471
```azurepowershell
5572
Connect-AzAccount
@@ -58,12 +75,12 @@ Select-AzSubscription -Subscription "<sub name>"
5875

5976
## Specify the HTTP header rewrite rule configuration
6077

61-
In this example, we'll modify a redirection URL by rewriting the location header in the HTTP response whenever the location header contains a reference to azurewebsites.net. To do this, we'll add a condition to evaluate whether the location header in the response contains azurewebsites.net. We'll use the pattern `(https?)://.*azurewebsites.net(.*)$`. And we'll use `{http_resp_Location_1}://contoso.com{http_resp_Location_2}` as the header value. This value will replace *azurewebsites.net* with *contoso.com* in the location header.
78+
In this example, we modify a redirection URL by rewriting the location header in the HTTP response whenever the location header contains a reference to azurewebsite.net. To do this modification, we add a condition to evaluate whether the location header in the response contains azurewebsite.net. We use the pattern `(https?)://.*azurewebsite.net(.*)$`. And we use `{http_resp_Location_1}://contoso.com{http_resp_Location_2}` as the header value. This value replaces *azurewebsite.net* with *contoso.com* in the location header.
6279

6380
```azurepowershell
6481
$responseHeaderConfiguration = New-AzApplicationGatewayRewriteRuleHeaderConfiguration -HeaderName "Location" -HeaderValue "{http_resp_Location_1}://contoso.com{http_resp_Location_2}"
6582
$actionSet = New-AzApplicationGatewayRewriteRuleActionSet -ResponseHeaderConfiguration $responseHeaderConfiguration
66-
$condition = New-AzApplicationGatewayRewriteRuleCondition -Variable "http_resp_Location" -Pattern "(https?):\/\/.*azurewebsites\.net(.*)$" -IgnoreCase
83+
$condition = New-AzApplicationGatewayRewriteRuleCondition -Variable "http_resp_Location" -Pattern "(https?):\/\/.*azurewebsite\.net(.*)$" -IgnoreCase
6784
$rewriteRule = New-AzApplicationGatewayRewriteRule -Name LocationHeader -ActionSet $actionSet -Condition $condition
6885
$rewriteRuleSet = New-AzApplicationGatewayRewriteRuleSet -Name LocationHeaderRewrite -RewriteRule $rewriteRule
6986
```
@@ -74,32 +91,51 @@ $rewriteRuleSet = New-AzApplicationGatewayRewriteRuleSet -Name LocationHeaderRew
7491
$appgw = Get-AzApplicationGateway -Name "AutoscalingAppGw" -ResourceGroupName "<rg name>"
7592
```
7693

77-
## Retrieve the configuration of your request routing rule
94+
## Retrieve request routing rule configuration
95+
96+
Get the specific request routing rule where you want to apply the header rewrite configuration:
7897

7998
```azurepowershell
8099
$reqRoutingRule = Get-AzApplicationGatewayRequestRoutingRule -Name rule1 -ApplicationGateway $appgw
81100
```
82101

83102
## Update the application gateway with the configuration for rewriting HTTP headers
84103

85-
In this example, the rewrite set would be associated instantly against a basic routing rule. In case of a path based routing rule, the association would not be enabled by default. The rewrite set can be enabled either via checking the paths on which it needs to be applied via portal or by providing a URL path map config specifying the RewriteRuleSet against each path option.
104+
In this example, the rewrite set would be associated instantly against a basic routing rule. In a path based routing rule, the association wouldn't be enabled by default. The rewrite set can be enabled either via -- checking the paths on which it needs to be applied via portal or by providing a URL path map config specifying the RewriteRuleSet against each path option.
86105

87106
```azurepowershell
88107
Add-AzApplicationGatewayRewriteRuleSet -ApplicationGateway $appgw -Name $rewriteRuleSet.Name -RewriteRule $rewriteRuleSet.RewriteRules
89108
Set-AzApplicationGatewayRequestRoutingRule -ApplicationGateway $appgw -Name $reqRoutingRule.Name -RuleType $reqRoutingRule.RuleType -BackendHttpSettingsId $reqRoutingRule.BackendHttpSettings.Id -HttpListenerId $reqRoutingRule.HttpListener.Id -BackendAddressPoolId $reqRoutingRule.BackendAddressPool.Id -RewriteRuleSetId $rewriteRuleSet.Id
90109
Set-AzApplicationGateway -ApplicationGateway $appgw
91110
```
92111

93-
## Delete a rewrite rule
112+
## Remove a rewrite rule (Optional)
94113

95-
```azurepowershell
114+
If you need to remove a rewrite rule set from your Application Gateway, use the following steps:
115+
116+
```azurepowershell-interactive
117+
# Retrieve the current Application Gateway configuration
96118
$appgw = Get-AzApplicationGateway -Name "AutoscalingAppGw" -ResourceGroupName "<rg name>"
119+
120+
# Remove the rewrite rule set association from the routing rule first
121+
$requestRoutingRule = Get-AzApplicationGatewayRequestRoutingRule -Name "rule1" -ApplicationGateway $appgw
122+
123+
# Clear the rewrite rule set reference
124+
$requestRoutingRule.RewriteRuleSet = $null
125+
126+
# Remove the rewrite rule set from the Application Gateway
97127
Remove-AzApplicationGatewayRewriteRuleSet -Name "LocationHeaderRewrite" -ApplicationGateway $appgw
98-
$requestroutingrule= Get-AzApplicationGatewayRequestRoutingRule -Name "rule1" -ApplicationGateway $appgw
99-
$requestroutingrule.RewriteRuleSet= $null
100-
set-AzApplicationGateway -ApplicationGateway $appgw
128+
129+
# Apply the changes
130+
Set-AzApplicationGateway -ApplicationGateway $appgw
131+
132+
Write-Output "Rewrite rule set removed successfully"
101133
```
102134

103135
## Next steps
104136

105-
To learn more about how to set up some common use cases, see [common header rewrite scenarios](./rewrite-http-headers-url.md).
137+
Now that you learned how to configure HTTP header rewrite rules, explore these related articles:
138+
139+
- **Common scenarios**: Learn about [common header rewrite scenarios](./rewrite-http-headers-url.md) including security headers, custom routing, and backend server integration patterns.
140+
141+
- **Monitoring and troubleshooting**: Set up [Application Gateway diagnostics](./application-gateway-diagnostics.md) to monitor header rewrite operations and troubleshoot issues.

articles/application-gateway/configuration-overview.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,35 +20,35 @@ This image illustrates an application that has three listeners. The first two ar
2020

2121
## Infrastructure
2222

23-
The Application Gateway infrastructure includes the virtual network, subnets, network security groups, and user defined routes.
23+
The Application Gateway infrastructure includes the virtual network, subnets, network security groups, and user-defined routes.
2424

2525
For more information, see [Application Gateway infrastructure configuration](configuration-infrastructure.md).
2626

2727

2828

2929
## Frontend IP address
3030

31-
You can configure the application gateway to have a public IP address, a private IP address, or both. A public IP is required when you host a back end that clients must access over the Internet via an Internet-facing virtual IP (VIP).
31+
You can configure the application gateway to have a public IP address, a private IP address, or both. A public IP is required when you host a backend that clients must access over the Internet via an Internet-facing virtual IP (VIP).
3232

3333
For more information, see [Application Gateway frontend IP address configuration](configuration-frontend-ip.md).
3434

3535
## Listeners
3636

37-
A listener is a logical entity that checks for incoming connection requests by using the port, protocol, host, and IP address. When you configure the listener, you must enter values for these that match the corresponding values in the incoming request on the gateway.
37+
A listener is a logical entity that checks for incoming connection requests by using the port, protocol, host, and IP address. When you configure the listener, you must enter values for these entities that match the corresponding values in the incoming request on the gateway.
3838

3939
For more information, see [Application Gateway listener configuration](configuration-listeners.md).
4040

4141
## Request routing rules
4242

43-
When you create an application gateway by using the Azure portal, you create a default rule (*rule1*). This rule binds the default listener (*appGatewayHttpListener*) with the default backend pool (*appGatewayBackendPool*) and the default backend HTTP settings (*appGatewayBackendHttpSettings*). After you create the gateway, you can edit the settings of the default rule or create new rules.
43+
When you create an application gateway by using the Azure portal, you create a default rule (*rule1*). This rule binds the default listener (*appGatewayHttpListener*) with the default backend pool (*appGatewayBackendPool*) and the default backend HTTP settings (*appGatewayBackendHttpSettings*). After you create the gateway, you can edit the settings of the default rule or create new rules.
4444

4545
For more information, see [Application Gateway request routing rules](configuration-request-routing-rules.md).
4646

47-
## HTTP settings
47+
## Backend settings
4848

49-
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.
49+
The application gateway routes traffic to the backend servers by using the configuration that you specify here. After you create a backend setting, you must associate it with one or more request-routing rules.
5050

51-
For more information, see [Application Gateway HTTP settings configuration](configuration-http-settings.md).
51+
For more information, see [Application Gateway backend settings configuration](configuration-http-settings.md).
5252

5353
## Backend pool
5454

@@ -58,10 +58,10 @@ After you create a backend pool, you must associate it with one or more request-
5858

5959
## Health probes
6060

61-
An application gateway monitors the health of all resources in its back end by default. But we strongly recommend that you create a custom probe for each backend HTTP setting to get greater control over health monitoring. To learn how to configure a custom probe, see [Custom health probe settings](application-gateway-probe-overview.md#custom-health-probe-settings).
61+
An application gateway monitors the health of all resources in its backend by default. But we strongly recommend that you create a custom probe for each backend HTTP setting to get greater control over health monitoring. To learn how to configure a custom probe, see [Custom health probe settings](application-gateway-probe-overview.md#custom-health-probe-settings).
6262

6363
> [!NOTE]
64-
> After you create a custom health probe, you need to associate it to a backend HTTP setting. A custom probe won't monitor the health of the backend pool unless the corresponding HTTP setting is explicitly associated with a listener using a rule.
64+
> After you create a custom health probe, you need to associate it to a backend HTTP setting. A custom probe doesn't monitor the health of the backend pool unless the corresponding HTTP setting is explicitly associated with a listener using a rule.
6565
6666
## Next steps
6767

0 commit comments

Comments
 (0)