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
+30-11Lines changed: 30 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -608,21 +608,40 @@ For more information, see [Preserve the original HTTP host name between a revers
608
608
609
609
### Scenario 10: If-elseif-else rules
610
610
611
-
The current rule engine in Azure Front Door does not natively support traditional conditional logic with "if-elseif-else" structures. Instead, all rules are independently evaluated as "if condition1 then action1," "if condition2 then action2," and so forth. This implies that if multiple conditions (e.g., condition1 and condition2) are simultaneously met, multiple corresponding actions (action1 and action2) will be executed.
612
-
However, it is possible to emulate an "if-elseif-else" that resembles the following:
613
-
- If condition1 is satisfied, execute action1.
614
-
- Else if condition2 is satisfied (but condition1 is not), execute action2.
615
-
- Else, execute a default action.
616
-
If multiple conditions (condition1, condition2, ..., conditionN) are satisfied simultaneously, only the first matching action is executed, effectively simulating traditional conditional branching. If none of the conditions are met, the default action will execute.
617
-
To configure this, create a new ruleset call it “IfElseifElseRuleset” and create rules as normal, the only change would be to check the Stop evaluating remaining rules box after each rule as shown below –
611
+
The Azure Front Door rules engine doesn't natively support traditional conditional logic with "if-elseif-else" structures. By default, all rules are independently evaluated as "if condition1 then action1," "if condition2 then action2," and so forth. When multiple conditions are met simultaneously, multiple corresponding actions are executed.
618
612
619
-
Note: Due to limitations of current ruleset implementation, this if-elseif-else paradigm will only work if the ruleset is attached as the final ruleset for that route as shown below.
620
-
Here is the Rule set configuration in Azure portal.
613
+
However, you can emulate "if-elseif-else" logic by using the **Stop evaluating remaining rules** feature to create conditional branching that resembles:
614
+
615
+
- If condition1 is satisfied, execute action1 and stop
616
+
- Else if condition2 is satisfied (but condition1 is not), execute action2 and stop
617
+
- Else if condition3 is satisfied (but condition1 and condition2 are not), execute action3 and stop
618
+
- Else, execute a default action
619
+
620
+
**How it works:** When multiple conditions would normally be satisfied simultaneously, only the first matching rule executes because rule evaluation stops after the first match. This effectively simulates traditional conditional branching.
621
+
622
+
**Configuration steps:**
623
+
624
+
1. Create a new ruleset (for example, "IfElseifElseRuleset")
625
+
2. Create rules in priority order, with the most specific conditions first
626
+
3. For each rule, check the **Stop evaluating remaining rules** option
627
+
628
+
:::image type="content" source="./media/rules-engine-scenarios/if-elseif-else-rules.png" alt-text="Screenshot that shows how to configure if-elseif-else rules." lightbox="./media/rules-engine-scenarios/if-elseif-else-rules.png":::
629
+
630
+
> [!IMPORTANT]
631
+
> This if-elseif-else paradigm only works if the ruleset is attached as the **final** ruleset for that route.
632
+
633
+
:::image type="content" source="./media/rules-engine-scenarios/if-elseif-else-rules-final.png" alt-text="Screenshot that shows how to place if-elseif-else rules as the final ruleset for the route." lightbox="./media/rules-engine-scenarios/if-elseif-else-rules-final.png":::
621
634
622
635
### Scenario 11: Removing query strings from incoming URLs using URL redirects
623
636
624
-
To remove query strings from incoming URLs, implement a 3xx URL redirect to guide users back to the AFD endpoint with the query strings removed. Please note, users will notice the change of the request URL with this operation.
625
-
Here is the configuration in rules engine in portal to strip the whole query string. If you need to strip part of it, you can adjust the offset/length as desired: Server variables - Azure Front Door | Microsoft Learn
637
+
You can remove query strings from incoming URLs by implementing a 3xx URL redirect that guides users back to the Azure Front Door endpoint with the query strings removed.
638
+
639
+
[!NOTE]
640
+
> Users will notice the change of the request URL with this operation.
641
+
642
+
The following example demonstrates how to remove the entire query string from incoming URLs. If you need to strip part of it, you can adjust the offset/length as desired. For more information, see [Server variable format](/azure/frontdoor/rule-set-server-variables#server-variable-format).
643
+
644
+
:::image type="content" source="./media/rules-engine-scenarios/remove-query-strings.png" alt-text="Screenshot that shows how to remove query strings from incoming URLs using URL 3xx redirects." lightbox="./media/rules-engine-scenarios/remove-query-strings.png":::
0 commit comments