You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/application-gateway/add-http-header-rewrite-rule-powershell.md
+66-30Lines changed: 66 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,51 +5,68 @@ services: application-gateway
5
5
author: mbender-ms
6
6
ms.service: azure-application-gateway
7
7
ms.topic: how-to
8
-
ms.date: 04/12/2019
8
+
ms.date: 07/09/2025
9
9
ms.author: mbender
10
10
ms.custom: devx-track-azurepowershell
11
11
# 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."
12
12
---
13
13
# Rewrite HTTP request and response headers with Azure Application Gateway - Azure PowerShell
14
14
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.
16
16
17
17
If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin.
18
18
19
-
## Before you begin
19
+
## Prerequisites
20
20
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:
23
22
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.
25
27
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.
27
30
28
-
1. Create the objects that are required for HTTP header rewrite:
31
+
## Understanding HTTP header rewrite components
29
32
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:
31
34
32
-
-**ResponseHeaderConfiguration**: Used to specify the response header fields that you intend to rewrite and the new value for the headers.
35
+
### Core components
33
36
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.
35
38
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.
37
40
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.
> Multiple conditions associated with an action use logical AND operation - all conditions must be met for the action to execute.
41
47
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.
43
49
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.
45
51
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.
47
54
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.
49
56
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
51
58
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:
## Specify the HTTP header rewrite rule configuration
60
77
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.
## Update the application gateway with the configuration for rewriting HTTP headers
84
103
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.
Write-Output "Rewrite rule set removed successfully"
101
133
```
102
134
103
135
## Next steps
104
136
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.
Copy file name to clipboardExpand all lines: articles/application-gateway/configuration-overview.md
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,35 +20,35 @@ This image illustrates an application that has three listeners. The first two ar
20
20
21
21
## Infrastructure
22
22
23
-
The Application Gateway infrastructure includes the virtual network, subnets, network security groups, and userdefined routes.
23
+
The Application Gateway infrastructure includes the virtual network, subnets, network security groups, and user-defined routes.
24
24
25
25
For more information, see [Application Gateway infrastructure configuration](configuration-infrastructure.md).
26
26
27
27
28
28
29
29
## Frontend IP address
30
30
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).
32
32
33
33
For more information, see [Application Gateway frontend IP address configuration](configuration-frontend-ip.md).
34
34
35
35
## Listeners
36
36
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.
38
38
39
39
For more information, see [Application Gateway listener configuration](configuration-listeners.md).
40
40
41
41
## Request routing rules
42
42
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.
44
44
45
45
For more information, see [Application Gateway request routing rules](configuration-request-routing-rules.md).
46
46
47
-
## HTTP settings
47
+
## Backend settings
48
48
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.
50
50
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).
52
52
53
53
## Backend pool
54
54
@@ -58,10 +58,10 @@ After you create a backend pool, you must associate it with one or more request-
58
58
59
59
## Health probes
60
60
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).
62
62
63
63
> [!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.
0 commit comments