Skip to content

Commit dfe9be4

Browse files
committed
Update Forwarding URL examples with wildcards
1 parent 248f991 commit dfe9be4

File tree

4 files changed

+52
-20
lines changed

4 files changed

+52
-20
lines changed
-23.5 KB
Loading
-17.9 KB
Loading

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

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -894,28 +894,34 @@ You configured a Page Rule permanently redirecting `www.example.com` to `example
894894

895895
**How to migrate**:
896896

897-
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:
898898

899-
<div class="DocsMarkdown--example">
899+
<div class="DocsMarkdown--example">
900900

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

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

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

913-
</div>
911+
</div>
914912

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

917915
3. If your tests succeed, delete the existing Page Rule.
918916

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+
919925
</TabItem> <TabItem label="visual guide">
920926

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

942948
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`:
943949

944-
<div class="DocsMarkdown--example">
950+
<div class="DocsMarkdown--example">
945951

946-
- **When incoming requests match**: Custom filter expression
952+
- **If incoming requests match**: Wildcard pattern
947953

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

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

959-
</div>
962+
</div>
960963

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

963966
3. If your tests succeed, delete the existing Page Rule.
964967

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+
965976
</TabItem> <TabItem label="visual guide">
966977

967978
| 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)