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/frontdoor/rules-engine-scenarios.md
+32-9Lines changed: 32 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -352,7 +352,7 @@ In some scenarios, you might need to add new segments or remove some segments wh
352
352
For example, if you want to redirect `https://domain.com/seg0/seg1/seg2/seg3` to `https://example.com/seg0/insert/seg2/seg3`. In this scenario, you replace URL path’s `{seg1}` with `/insert/` while preserving the rest of the URL path. Azure Front Door achieves the desired redirect by combining values extracted from server variables (URL segments) and combining static string segment `/insert/`. You can use `Int32.Max (2147483647)` for URL segment’s length field to keep all segments from *seg2* to *segn*. For more information, see [Server variable format](/azure/frontdoor/rule-set-server-variables#server-variable-format).
353
353
354
354
> [!NOTE]
355
-
> Similar configuration can be done for URL rewrite action by inputting source pattern as `/` and destination as `/{url_path:seg0}/insert/{url_path:seg2:2147483647}`as shown for redirect action in the following portal example.
355
+
> Similar configuration can be done for URL rewrite action by inputting source pattern as `/` and destination as `/{url_path:seg0}/insert/{url_path:seg2:2147483647}` for redirect action as shown in the following portal example.
356
356
357
357
:::image type="content" source="./media/rules-engine-scenarios/redirect-url-path-modification.png" alt-text="Screenshot that shows how to redirect with URL path modification while preserving part of the URL path." lightbox="./media/rules-engine-scenarios/redirect-url-path-modification.png":::
358
358
@@ -386,8 +386,16 @@ For example, if you want to redirect `https://domain.com/seg0/seg1/seg2/seg3` to
386
386
387
387
### Scenario 6: Redirect by removing fixed parts of a URL path
388
388
389
-
A user needs to remove fixed segments of known size from a URL like, country code (us) or locale (en-us), and preserve the rest of the URL path.
390
-
For example, if you want to redirect https://domain.com/us/seg1/seg2/seg3/ to https://example.com/seg1/seg2/seg3/, i.e. remove country code /us/ and keep the rest of the URL path as-is. Use the {variable:offset} which includes the server variable after a specific offset, until the end of the variable. For more information, see [Server variable format](/azure/frontdoor/rule-set-server-variables#server-variable-format).
389
+
You can remove fixed segments of known size from a URL path, such as country codes (us) or locales (en-us), while preserving the rest of the URL path.
390
+
391
+
For example, if you want to redirect `https://domain.com/us/seg1/seg2/seg3/` to `https://example.com/seg1/seg2/seg3/`, you need to remove the country code `/us/` and keep the rest of the URL path unchanged.
392
+
393
+
To achieve this, use `{variable:offset} `, which includes the server variable after a specific offset, until the end of the variable. For more information, see [Server variable format](/azure/frontdoor/rule-set-server-variables#server-variable-format).
394
+
395
+
> [!NOTE]
396
+
> Similar configuration can be done for URL rewrite action by inputting source pattern as `/` and destination as `/“{url_path:3}` for redirect action as shown in the following portal example.
397
+
398
+
:::image type="content" source="./media/rules-engine-scenarios/redirect-remove-fixed-part.png" alt-text="Screenshot that shows how to redirect by removing fixed parts of a URL path." lightbox="./media/rules-engine-scenarios/redirect-remove-fixed-part.png":::
391
399
392
400
```json
393
401
{
@@ -431,10 +439,18 @@ For example, if you want to redirect https://domain.com/us/seg1/seg2/seg3/ to ht
431
439
}
432
440
```
433
441
434
-
### Scenario 7: URL Rewrite by removing one or more segments of URL path
442
+
### Scenario 7: URL rewrite by removing one or more segments of URL path
443
+
444
+
You can remove one or more segments from a URL path, such as country codes (us) or locales (en-us), while preserving the rest of the URL path.
445
+
446
+
For example, if you want to rewrite `https://domain.com/us/seg1/seg2/seg3/` to `https://origin.com/seg2/seg3/`, you need to remove both the country code and an additional segment `/us/seg1/` while keeping the rest of the URL path intact.
447
+
448
+
To achieve this, use the `{url_path:seg#:length}` server variable format to capture specific URL segments starting from a particular segment number. In this example, use `{url_path:seg2:2147483647}` to capture all segments starting from `seg2` to the end. The value `2147483647` (Int32.Max) ensures all remaining segments are included. For more information, see [Server variable format](/azure/frontdoor/rule-set-server-variables#server-variable-format).
435
449
436
-
Users need to remove segments from a URL like, country code (us) or locale (en-us), and also preserve the rest of the URL path.
437
-
For example, if you want to rewrite https://domain.com/us/seg1/seg2/seg3/ to https://origin.com/seg2/seg3/, i.e. remove country code and an additional segment /us/seg1/ and keep the rest of the URL path.
450
+
:::image type="content" source="./media/rules-engine-scenarios/rewrite-url-remove-segments.png" alt-text="Screenshot that shows how to use URL rewrite to remove one or more segments of URL path." lightbox="./media/rules-engine-scenarios/rewrite-url-remove-segments.png":::
451
+
452
+
> [!NOTE]
453
+
> When using server variables like `{url_path}` in the **Destination** field, the **Preserve unmatched path** setting becomes less relevant because server variables give you explicit control over which parts of the URL path to include.
438
454
439
455
```json
440
456
{
@@ -466,9 +482,16 @@ For example, if you want to rewrite https://domain.com/us/seg1/seg2/seg3/ to htt
466
482
467
483
### Scenario 8: Use regex to reduce the number of rule conditions and avoid hitting limits
468
484
469
-
Using regex in rule conditions can reduce the number of rules, which can be a blocker due to rule limits for some customers needing conditions or actions for hundreds of their clients.
470
-
For example, if a customer wants identify their clients with an ID pattern to be allowed to access a resource behind AFD, then they will be sending a header like x-client-id: SN1234-ABCD56 which is of the format
Using regex in rule conditions can significantly reduce the number of rules required, which helps avoid rule limits that can be a blocker for customers who need conditions or actions for hundreds of clients.
486
+
487
+
For example, if a customer wants to identify their clients with a specific ID pattern to allow access to a resource behind Azure Front Door, clients send a header like `x-client-id: SN1234-ABCD56`. This header follows a specific format: `x-client-id: <SN + 4 digits + - + 4 uppercase letters + 2 digits>`.
488
+
489
+
Instead of creating individual rules for each possible client ID, you can use a single regex pattern `^SN[0-9]{4}-[A-Z]{4}[0-9]{2}$` to match all valid client IDs in one rule, for example, `SN1234-ABCD56`, `SN0001-ZYXW99`, `SN2025-QWER12`, `SN9876-MNOP34`, `SN3141-TEST42`, etc. This approach allows you to handle hundreds of different client IDs with a single rule configuration.
490
+
491
+
:::image type="content" source="./media/rules-engine-scenarios/regex-client-id-pattern.png" alt-text="Screenshot that shows how to use regex to match client ID patterns." lightbox="./media/rules-engine-scenarios/regex-client-id-pattern.png":::
492
+
493
+
> [!NOTE]
494
+
> You can use [regex101](https://regex101.com/) to test and validate your regex patterns before implementing them in Azure Front Door.
0 commit comments