Skip to content

Commit 6c8ec20

Browse files
committed
tweaks to scenario 1
1 parent ffd80d3 commit 6c8ec20

File tree

2 files changed

+72
-70
lines changed

2 files changed

+72
-70
lines changed
53.6 KB
Loading

articles/frontdoor/rules-engine-scenarios.md

Lines changed: 72 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -112,85 +112,87 @@ Managing redirects is critical for search engine optimization (SEO), user experi
112112

113113
- **Redirect based on dynamic-length URL path segments:** When the URL path segment has a dynamic length, you can extract it using the `{url_path:seg#}`. For more information, see [Server variable format](/azure/frontdoor/rule-set-server-variables#server-variable-format).
114114

115-
For example, if a tenant ID or location is embedded in the URL segment, such as: `https://api.contoso.com/{tenantId}/xyz`, you can extract `{tenantId}` from the URL and decide the correct redirect to use in the format of `tenantId.backend.com/xyz` with server variable `{url_path:seg0}.backend.com` in the redirect destination host.
115+
For example, if a tenant ID or location is embedded in the URL segment, such as: `https://api.contoso.com/{tenantId}/xyz`, you can extract `{tenantId}` from the URL and decide the correct redirect in the format of `tenantId.backend.com/xyz` with server variable `{url_path:seg0}.backend.com` in the redirect destination host.
116116

117-
This method avoids creating separate rules for each tenant ID, enabling more efficient configuration. In addition to ARM templates, you can also use Azure CLI or PowerShell in this approach.
118-
helps reduce the number of rules needed where you don’t need to create one rule for each tenant ID. This is currently supported by ARM templates and command line tools.
117+
This method avoids creating separate rules for each tenant ID, enabling more efficient configuration.
119118

120-
121-
```json
122-
{
123-
"type": "Microsoft.Cdn/profiles/rulesets/rules",
124-
"apiVersion": "2025-04-15",
125-
"name": "[concat(parameters('profiles_rulesengineblog_name'), '/RulesBlogScenarios/RedirectURLSegmentCapture')]",
126-
"dependsOn": [
127-
"[resourceId('Microsoft.Cdn/profiles/rulesets', parameters('profiles_rulesengineblog_name'), 'RulesBlogScenarios')]",
128-
"[resourceId('Microsoft.Cdn/profiles', parameters('profiles_rulesengineblog_name'))]"
129-
],
130-
"properties": {
131-
"order": 101,
132-
"conditions": [],
133-
"actions": [
134-
{
135-
"name": "UrlRedirect",
136-
"parameters": {
137-
"typeName": "DeliveryRuleUrlRedirectActionParameters",
138-
"redirectType": "PermanentRedirect",
139-
"destinationProtocol": "MatchRequest",
140-
"customPath": "/xyz",
141-
"customHostname": "{url_path:seg0}.backend.com"
142-
}
143-
}
119+
```json
120+
{
121+
"type": "Microsoft.Cdn/profiles/rulesets/rules",
122+
"apiVersion": "2025-04-15",
123+
"name": "[concat(parameters('profiles_rulesengineblog_name'), '/RulesBlogScenarios/RedirectURLSegmentCapture')]",
124+
"dependsOn": [
125+
"[resourceId('Microsoft.Cdn/profiles/rulesets', parameters('profiles_rulesengineblog_name'), 'RulesBlogScenarios')]",
126+
"[resourceId('Microsoft.Cdn/profiles', parameters('profiles_rulesengineblog_name'))]"
144127
],
145-
"matchProcessingBehavior": "Continue"
128+
"properties": {
129+
"order": 101,
130+
"conditions": [],
131+
"actions": [
132+
{
133+
"name": "UrlRedirect",
134+
"parameters": {
135+
"typeName": "DeliveryRuleUrlRedirectActionParameters",
136+
"redirectType": "PermanentRedirect",
137+
"destinationProtocol": "MatchRequest",
138+
"customPath": "/xyz",
139+
"customHostname": "{url_path:seg0}.backend.com"
140+
}
141+
}
142+
],
143+
"matchProcessingBehavior": "Continue"
144+
}
146145
}
147-
}
148-
```
146+
```
149147

150-
- To redirect requests to different origins using part of the incoming hostnames, you can capture part of the incoming hostname https://[tenantName].poc.contoso.com/GB and redirect to s1.example.com/Buyer/Main?realm=[tenantName]&examplename=example1, using the {hostname:0:-16} to capture the offset and length in server variable. You can learn more about the server variable formats in Server variables - Azure Front Door | Microsoft Learn.
148+
- **Redirect based on part of the incoming hostname:** You can redirect requests to different origins by extracting part of the incoming hostname.
151149

152-
```json
153-
{
154-
"type": "Microsoft.Cdn/profiles/rulesets/rules",
155-
"apiVersion": "2025-04-15",
156-
"name": "[concat(parameters('profiles_rulesengineblog_name'), '/RulesBlogScenarios/RedirectHostnameCapture')]",
157-
"dependsOn": [
158-
"[resourceId('Microsoft.Cdn/profiles/rulesets', parameters('profiles_rulesengineblog_name'), 'RulesBlogScenarios')]",
159-
"[resourceId('Microsoft.Cdn/profiles', parameters('profiles_rulesengineblog_name'))]"
160-
],
161-
"properties": {
162-
"order": 102,
163-
"conditions": [
164-
{
165-
"name": "HostName",
166-
"parameters": {
167-
"typeName": "DeliveryRuleHostNameConditionParameters",
168-
"operator": "EndsWith",
169-
"negateCondition": false,
170-
"matchValues": [
171-
"poc.contoso.com"
172-
],
173-
"transforms": []
174-
}
175-
}
150+
For example, you can capture `tenantName` from `https://[tenantName].poc.contoso.com/GB` to redirect the request to `s1.example.com/Buyer/Main?realm=[tenantName]&examplename=example1` using the offset and length in server variable in the format of `{hostname:0:-16}`. For more information, see [Server variable format](/azure/frontdoor/rule-set-server-variables#server-variable-format)
151+
152+
:::image type="content" source="./media/rules-engine-scenarios/redirect-incoming-hostname.png" alt-text="Screenshot that shows how to use incoming hostname to redirect URL." lightbox="./media/rules-engine-scenarios/redirect-incoming-hostname.png":::
153+
154+
```json
155+
{
156+
"type": "Microsoft.Cdn/profiles/rulesets/rules",
157+
"apiVersion": "2025-04-15",
158+
"name": "[concat(parameters('profiles_rulesengineblog_name'), '/RulesBlogScenarios/RedirectHostnameCapture')]",
159+
"dependsOn": [
160+
"[resourceId('Microsoft.Cdn/profiles/rulesets', parameters('profiles_rulesengineblog_name'), 'RulesBlogScenarios')]",
161+
"[resourceId('Microsoft.Cdn/profiles', parameters('profiles_rulesengineblog_name'))]"
176162
],
177-
"actions": [
178-
{
179-
"name": "UrlRedirect",
180-
"parameters": {
181-
"typeName": "DeliveryRuleUrlRedirectActionParameters",
182-
"redirectType": "PermanentRedirect",
183-
"destinationProtocol": "MatchRequest",
184-
"customQueryString": "realm={hostname:0:-16}&examplename=example1",
185-
"customPath": "/Buyer/Main",
186-
"customHostname": "s1.example.com"
163+
"properties": {
164+
"order": 102,
165+
"conditions": [
166+
{
167+
"name": "HostName",
168+
"parameters": {
169+
"typeName": "DeliveryRuleHostNameConditionParameters",
170+
"operator": "EndsWith",
171+
"negateCondition": false,
172+
"matchValues": [
173+
"poc.contoso.com"
174+
],
175+
"transforms": []
176+
}
187177
}
188-
}
189-
],
190-
"matchProcessingBehavior": "Continue"
178+
],
179+
"actions": [
180+
{
181+
"name": "UrlRedirect",
182+
"parameters": {
183+
"typeName": "DeliveryRuleUrlRedirectActionParameters",
184+
"redirectType": "PermanentRedirect",
185+
"destinationProtocol": "MatchRequest",
186+
"customQueryString": "realm={hostname:0:-16}&examplename=example1",
187+
"customPath": "/Buyer/Main",
188+
"customHostname": "s1.example.com"
189+
}
190+
}
191+
],
192+
"matchProcessingBehavior": "Continue"
193+
}
191194
}
192-
}
193-
```
195+
```
194196

195197
### Scenario 2: Populate or modify a response header based on a request header value
196198

0 commit comments

Comments
 (0)