Skip to content

Commit 93b5b3f

Browse files
authored
[Rules] Use wildcard pattern in migration guide examples (#17461)
* Update Migrate Always Use HTTPS example * Update Forwarding URL examples with wildcards
1 parent 6fed1ab commit 93b5b3f

File tree

5 files changed

+60
-30
lines changed

5 files changed

+60
-30
lines changed
-42.9 KB
Loading
-23.5 KB
Loading
-17.9 KB
Loading

src/content/docs/rules/reference/page-rules-migration.mdx

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -137,23 +137,21 @@ You configured a Page Rule to perform an automatic redirect from HTTP to HTTPS f
137137

138138
**How to migrate**:
139139

140-
1. [Create a single redirect](/rules/url-forwarding/single-redirects/create-dashboard/) to always redirect HTTP requests to HTTPS for any hostname that contains `example.com`:
140+
1. [Create a single redirect](/rules/url-forwarding/single-redirects/create-dashboard/) to always redirect HTTP requests to HTTPS. You can select the **Redirect from HTTP to HTTPS** rule template or enter the following rule configuration:
141141

142-
<div class="DocsMarkdown--example">
142+
<div class="DocsMarkdown--example">
143143

144-
- **When incoming requests match**: Custom filter expression
144+
- **If incoming requests match**: Wildcard pattern
145145

146-
- Using the Expression Builder:<br/>
147-
`Hostname contains "example.com" AND SSL/HTTPS is off`
148-
- Using the Expression Editor:<br/>
149-
`(http.host contains "example.com" and not ssl)`
146+
- **Request URL**: `http://*`
150147

151148
- **Then**:
152-
- **Type**: _Dynamic_
153-
- **Expression**: `concat("https://", http.host, http.request.uri.path)`
149+
150+
- **Target URL**: `https://${1}`
154151
- **Status code**: _301_
152+
- **Preserve query string**: Enabled
155153

156-
</div>
154+
</div>
157155

158156
2. Turn off your existing Page Rule and validate the behavior of the redirect you created.
159157

@@ -896,28 +894,34 @@ You configured a Page Rule permanently redirecting `www.example.com` to `example
896894

897895
**How to migrate**:
898896

899-
1. [Create a single redirect](/rules/url-forwarding/single-redirects/create-dashboard/) to permanently redirect requests from `www.example.com` to `example.com`:
897+
1. [Create a single redirect](/rules/url-forwarding/single-redirects/create-dashboard/) to permanently redirect requests from `https://www.example.com` to `https://example.com`. You can select the **Redirect from WWW to Root** rule template or enter the following rule configuration:
900898

901-
<div class="DocsMarkdown--example">
899+
<div class="DocsMarkdown--example">
902900

903-
- **When incoming requests match**: Custom filter expression
901+
- **If incoming requests match**: Wildcard pattern
904902

905-
- Using the Expression Builder:<br/>
906-
`Hostname equals "www.example.com"`
907-
- Using the Expression Editor:<br/>
908-
`(http.host eq "www.example.com")`
903+
- **Request URL**: `https://www.example.com/*`
909904

910905
- **Then**:
911-
- **Type**: _Dynamic_
912-
- **Expression**: `concat("https://example.com", http.request.uri.path)`
906+
907+
- **Target URL**: `https://example.com/${1}`
913908
- **Status code**: _301_
909+
- **Preserve query string**: Enabled
914910

915-
</div>
911+
</div>
916912

917913
2. Turn off your existing Page Rule and validate the behavior of the redirect you created.
918914

919915
3. If your tests succeed, delete the existing Page Rule.
920916

917+
<Render
918+
file="page-rules-migration-wildcard-notice"
919+
params={{
920+
requestUrl: "http*://www.example.com/*",
921+
targetUrl: "https://example.com/${2}",
922+
}}
923+
/>
924+
921925
</TabItem> <TabItem label="visual guide">
922926

923927
| Page Rules configuration | Migrate to a single redirect |
@@ -943,27 +947,32 @@ You configured a Page Rule permanently redirecting `example.com/old-path` to `ex
943947

944948
1. [Create a single redirect](/rules/url-forwarding/single-redirects/create-dashboard/) to permanently redirect requests for `example.com/old-path` to `example.com/new-path`:
945949

946-
<div class="DocsMarkdown--example">
950+
<div class="DocsMarkdown--example">
947951

948-
- **When incoming requests match**: Custom filter expression
952+
- **If incoming requests match**: Wildcard pattern
949953

950-
- Using the Expression Builder:<br/>
951-
`Hostname equals "example.com" AND URI Path starts with "/old-path/"`
952-
- Using the Expression Editor:<br/>
953-
`(http.host eq "example.com" and starts_with(http.request.uri.path, "/old-path/"))`
954+
- **Request URL**: `https://example.com/old-path/*`
954955

955956
- **Then**:
956-
- **Type**: _Dynamic_
957-
- **Expression**: `concat("/new-path/", substring(http.request.uri.path, 10))`<br/>
958-
(where `10` (start byte value) is the length of `/old-path/`)
957+
958+
- **Target URL**: `https://example.com/new-path/${1}`
959959
- **Status code**: _301_
960+
- **Preserve query string**: Enabled
960961

961-
</div>
962+
</div>
962963

963964
2. Turn off your existing Page Rule and validate the behavior of the redirect you created.
964965

965966
3. If your tests succeed, delete the existing Page Rule.
966967

968+
<Render
969+
file="page-rules-migration-wildcard-notice"
970+
params={{
971+
requestUrl: "http*://example.com/old-path/*",
972+
targetUrl: "https://example.com/new-path/${2}",
973+
}}
974+
/>
975+
967976
</TabItem> <TabItem label="visual guide">
968977

969978
| Page Rules configuration | Migrate to a single redirect |
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
params:
3+
- requestUrl
4+
- targetUrl
5+
---
6+
7+
import { Details } from "~/components";
8+
9+
<Details header="Notes about the rule equivalence">
10+
11+
The provided example using Single Redirects is not an exact match for the previously existing Page Rule in the same example.
12+
13+
The exact equivalent would need to match both HTTP and HTTPS incoming requests, which you could achieve using a wildcard pattern like the following (notice the extra `*` after `http`):
14+
15+
- **Request URL**: <code>{props.requestUrl}</code>
16+
17+
This would require you to also change the **Target URL** to use the second wildcard capture group instead of the first one (corresponding to the text captured by second `*` in the wildcard pattern above):
18+
19+
- **Target URL**: <code>{props.targetUrl}</code>
20+
21+
</Details>

0 commit comments

Comments
 (0)