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
title: Route traffic using parameterbased path selection in portal - Azure Application Gateway
3
-
description: Learn how to use the Azure portal to configure an Azure Application Gateway to choose the backend pool based on the value of a header, part of URL, or query string in the request.
2
+
title: Route traffic using parameter-based path selection in portal - Azure Application Gateway
3
+
description: Use the Azure portal to configure an application gateway to choose the backend pool based on the value of a header, part of a URL, or a query string in the request.
This article describes how to use the Azure portal to configure an [Application Gateway v2 SKU](./application-gateway-autoscaling-zone-redundant.md) instance to perform parameterbased path selection by combining the capabilities of URL Rewrite with path-based routing.
14
+
This article describes how to use the Azure portal to configure an [Azure Application Gateway v2 SKU](./application-gateway-autoscaling-zone-redundant.md) instance to perform parameter-based path selection by combining the capabilities of URL Rewrite with path-based routing.
15
15
16
16
If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin.
17
17
18
18
## Before you begin
19
19
20
-
You need to have an Application Gateway v2 SKU instance to complete the steps in this article. URL rewrite and rewriting headers aren'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
-
20
+
You need to have an Application Gateway v2 SKU instance to finish the steps in this article. URL Rewrite and rewriting headers aren'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.
22
21
23
22
## Sign in to Azure
24
23
25
24
Sign in to the [Azure portal](https://portal.azure.com/) with your Azure account.
26
25
27
-
## Configure parameter based path selection
28
-
29
-
For this example, you have a shopping website and the product category is passed as query string in the URL, and you want to route the request to backend based on the query string, then:
30
-
31
-
**Step 1:** Create a path-map as shown in the following image:
26
+
## Configure parameter-based path selection
32
27
33
-
:::image type="content" source="./media/rewrite-http-headers-url/url-scenario1-1.png" alt-text="A screenshot of URL rewrite scenario 1-1.":::
28
+
For this example, you have a shopping website. The product category is passed as a query string in the URL. To route the request to the backend based on the query string, follow these steps.
34
29
35
-
**Step 2 (a):**Create a rewrite set which has 3 rewrite rules:
30
+
1.Create a path map.
36
31
37
-
* The first rule has a condition that checks the *query_string* variable for *category=shoes* and has an action that rewrites the URL path to /*listing1* and has **Reevaluate path map** enabled
32
+
:::image type="content" source="./media/rewrite-http-headers-url/url-scenario1-1.png" alt-text="Screenshot that shows a URL Rewrite scenario 1-1.":::
38
33
39
-
* The second rule has a condition that checks the *query_string* variable for *category=bags* and has an action that rewrites the URL path to /*listing2* and has **Reevaluate path map** enabled
34
+
1. Create a rewrite set that has three rewrite rules:
40
35
41
-
* The third rule has a condition that checks the *query_string* variable for *category=accessories* and has an action that rewrites the URL path to /*listing3* and has **Reevaluate path map** enabled
36
+
* The first rule has a condition that checks the `query_string` variable for `category=shoes`. An action rewrites the URL path to `/listing1`. **Reevaluate path map** is enabled.
37
+
* The second rule has a condition that checks the `query_string` variable for `category=bags`. An action rewrites the URL path to `/listing2`. **Reevaluate path map** is enabled.
38
+
* The third rule has a condition that checks the `query_string` variable for `category=accessories`. An action rewrites the URL path to `/listing3`. **Reevaluate path map** is enabled.
42
39
43
-
:::image type="content" source="./media/rewrite-http-headers-url/url-scenario1-2.png" alt-text="A screenshot of URL rewrite scenario 1-2.":::
40
+
:::image type="content" source="./media/rewrite-http-headers-url/url-scenario1-2.png" alt-text="Screenshot that shows the URL Rewrite scenario 1-2.":::
44
41
45
-
46
-
**Step 2 (b):** Associate this rewrite set with the default path of the previous path-based rule:
42
+
1. Associate this rewrite set with the default path of the previous path-based rule.
47
43
48
-
:::image type="content" source="./media/rewrite-http-headers-url/url-scenario1-3.png" alt-text="A screenshot of URL rewrite scenario 1-3.":::
44
+
:::image type="content" source="./media/rewrite-http-headers-url/url-scenario1-3.png" alt-text="Screenshot that shows the URL rewrite scenario 1-3.":::
49
45
50
-
If the user requests *contoso.com/listing?category=any*, then it's matched with the default path since none of the path patterns in the path map (/listing1, /listing2, /listing3) are matched. Since you associated the previous rewrite set with this path, this rewrite set is evaluated. Because the query string doesn't match the condition in any of the 3 rewrite rules in this rewrite set, no rewrite action takes place. Therefore, the request is routed unchanged to the backend associated with the default path (which is *GenericList*).
46
+
If the user requests `contoso.com/listing?category=any`, it's matched with the default path because the path patterns in the path map (`/listing1`, /`listing2`, /`listing3`) don't match. Because you associated the previous rewrite set with this path, this rewrite set is evaluated. The query string doesn't match the condition in any of the three rewrite rules in this rewrite set, so no rewrite action takes place. The request is routed unchanged to the backend associated with the default path (which is `GenericList`).
51
47
52
-
If the user requests *contoso.com/listing?category=shoes*, then the default path is matched. However, in this case, the condition in the first rule matches. Therefore, the action associated with the condition is executed, which rewrites the URL path to /*listing1*and reevaluates the path-map. When the path-map is reevaluated, the request matches the path associated with pattern */listing1* and the request is routed to the backend associated with this pattern (ShoesListBackendPool).
48
+
If the user requests `contoso.com/listing?category=shoes`, the default path is matched. In this case, the condition in the first rule matches. The action associated with the condition is executed, which rewrites the URL path to `/listing1`and reevaluates the pathmap. When the pathmap is reevaluated, the request matches the path associated with the pattern `/listing1`. The request is routed to the backend associated with this pattern (`ShoesListBackendPool`).
53
49
54
50
> [!NOTE]
55
-
> This scenario can be extended to any header or cookie value, URL path, query string or server variables based on the conditions defined and essentially enables you to route requests based on those conditions.
51
+
> You can extend this scenario to any header or cookie value, URL path, query string, or server variables based on the conditions defined. You can then route requests based on those conditions.
56
52
57
-
## Next steps
53
+
## Related content
58
54
59
-
To learn more about how to set up some common use cases, see [common header rewrite scenarios](./rewrite-http-headers-url.md).
55
+
To learn more about how to set up some common use cases, see [Common header rewrite scenarios](./rewrite-http-headers-url.md).
title: Rewrite HTTP request and response headers in portal - Azure Application Gateway
3
-
description: Learn how to use the Azure portal to configure an Azure Application Gateway to rewrite the HTTP headers in the requests and responses passing through the gateway
3
+
description: Use the Azure portal to configure an application gateway to rewrite the HTTP headers in the requests and responses that pass through the gateway.
4
4
services: application-gateway
5
5
author: greg-lindsay
6
6
ms.service: azure-application-gateway
@@ -9,120 +9,109 @@ ms.date: 11/13/2019
9
9
ms.author: greglin
10
10
ms.custom: mvc
11
11
---
12
+
12
13
# Rewrite HTTP request and response headers with Azure Application Gateway - Azure portal
13
14
14
-
This article describes how to use the Azure portal 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 the Azure portal to configure an [Azure Application Gateway v2 SKU](./application-gateway-autoscaling-zone-redundant.md) instance to rewrite the HTTP headers in requests and responses.
15
16
16
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.
17
18
18
19
## Before you begin
19
20
20
-
You need to have an Application Gateway v2 SKU instance to complete the steps in this article. 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
+
You need to have an Application Gateway v2 SKU instance to finish the steps in this article. 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
22
22
23
## Create required objects
23
24
24
-
To configure HTTP header rewrite, you need to complete these steps.
25
+
To configure HTTP header rewrite, follow these steps.
25
26
26
-
1. Create the objects that are required for HTTP header rewrite:
27
+
1. Create the objects that are required for an HTTP header rewrite:
27
28
28
29
-**Rewrite action**: Used to specify the request and request header fields that you intend to rewrite and the new value for the headers. You can associate one or more rewrite conditions with a rewrite action.
30
+
-**Rewrite 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.
29
31
30
-
-**Rewrite 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.
31
-
32
-
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.
-**Rule sequence**: Helps determine the order in which the 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.
32
+
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.
-**Rule sequence**: Helps determine the order in which the 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 nondeterministic.
38
36
-**Rewrite set**: Contains multiple rewrite rules that will be associated with a request routing rule.
39
37
40
-
2. Attach the rewrite set 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.
38
+
1. Attach the rewrite set to a routing rule. The rewrite configuration is attached to the source listener via the routing rule.
39
+
40
+
- When you use a basic routing rule, the header rewrite configuration is associated with a source listener and is a global header rewrite.
41
+
- 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.
41
42
42
43
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.
43
44
44
45
## Sign in to Azure
45
46
46
47
Sign in to the [Azure portal](https://portal.azure.com/) with your Azure account.
47
48
48
-
## Configure header rewrite
49
+
## Configure a header rewrite
49
50
50
-
In this example, we'll modify a redirection URL by rewriting the location header in the HTTP response sent by a backend application.
51
+
In this example, we modify a redirection URL by rewriting the location header in the HTTP response sent by a backend application.
51
52
52
53
1. Select **All resources**, and then select your application gateway.

59
60
60
-
4. Provide a name for the rewrite set and associate it with a routing rule:
61
+
1. Provide a name for the rewrite set and associate it with a routing rule:
61
62
62
-
- Enter the name for the rewrite set in the **Name** box.
63
-
- Select one or more of the rules listed in the **Associated routing rules** list. You can select only rules that haven't been associated with other rewrite sets. The rules that have already been associated with other rewrite sets are dimmed.
64
-
- Select **Next**.
63
+
1. In the **Name** box, enter the name for the rewrite set.
64
+
1. In the **Associated routing rules** list, select one or more rules. Select only rules not already associated with other rewrite sets. Rules already associated with other rewrite sets are dimmed.
65
+
1. Select **Next**.
65
66
66
-

6. In this example, we'll rewrite the location header only when it contains a reference to azurewebsites.net. To do this, add a condition to evaluate whether the location header in the response contains azurewebsites.net:
79
-
80
-
- Select **Add condition** and then select the box containing the **If** instructions to expand it.
81
-
82
-

83
-
84
-
- In the **Type of variable to check** list, select **HTTP header**.
85
-
86
-
- In the **Header type** list, select **Response**.
87
-
88
-
- Because in this example we're evaluating the location header, which is a common header, select **Common header** under **Header name**.
89
-
90
-
- In the **Common header** list, select **Location**.
67
+

91
68
92
-
- Under **Case-sensitive**, select **No**.
69
+
1. Create a rewrite rule:
93
70
94
-
- In the **Operator** list, select **equal (=)**.
71
+
1. Select **Add rewrite rule**.
95
72
96
-
- Enter a regular expression pattern. In this example, we'll use the pattern `(https?):\/\/.*azurewebsites.net(.*)$`.
73
+

97
74
98
-
- Select **OK**.
75
+
1. In the **Rewrite rule name** box, enter a name for the rewrite rule. In the **Rule sequence** box, enter a number.
99
76
100
-

77
+

101
78
102
-
7. Add an action to rewrite the location header:
79
+
1. In this example, we rewrite the location header only when it contains a reference to `azurewebsites.net`. To do this step, add a condition to evaluate whether the location header in the response contains `azurewebsites.net`:
103
80
104
-
- In the **Action type** list, select **Set**.
81
+
1. Select **Add condition**, and then select the box containing the **If** instructions to expand it.
105
82
106
-
- In the **Header type** list, select **Response**.
83
+

107
84
108
-
- Under **Header name**, select **Common header**.
85
+
1. In the **Type of variable to check** list, select **HTTP header**.
86
+
1. In the **Header type** list, select **Response**.
87
+
1. Under **Header name**, select **Common header**. In this example, we're evaluating the location header, which is a common header.
88
+
1. In the **Common header** list, select **Location**.
89
+
1. Under **Case-sensitive**, select **No**.
90
+
1. In the **Operator** list, select **equal (=)**.
91
+
1. Enter a regular expression pattern. In this example, we use the pattern `(https?):\/\/.*azurewebsites.net(.*)$`.
92
+
1. Select **OK**.
109
93
110
-
- In the **Common header** list, select **Location**.
94
+

111
95
112
-
- Enter the header value. In this example, 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.
96
+
1. Add an action to rewrite the location header:
113
97
114
-
- Select **OK**.
98
+
1. In the **Action type** list, select **Set**.
99
+
1. In the **Header type** list, select **Response**.
100
+
1. Under **Header name**, select **Common header**.
101
+
1. In the **Common header** list, select **Location**.
102
+
1. Enter the header value. In this example, we use `{http_resp_Location_1}://contoso.com{http_resp_Location_2}` as the header value. This value replaces `azurewebsites.net` with `contoso.com` in the location header.
103
+
1. Select **OK**.
115
104
116
-

105
+

0 commit comments