Skip to content

Commit

Permalink
[Rules] Use wildcard pattern in migration guide examples (#17461)
Browse files Browse the repository at this point in the history
* Update Migrate Always Use HTTPS example
* Update Forwarding URL examples with wildcards
  • Loading branch information
pedrosousa authored Oct 10, 2024
1 parent 6fed1ab commit 93b5b3f
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 30 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
69 changes: 39 additions & 30 deletions src/content/docs/rules/reference/page-rules-migration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -137,23 +137,21 @@ You configured a Page Rule to perform an automatic redirect from HTTP to HTTPS f

**How to migrate**:

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

<div class="DocsMarkdown--example">
<div class="DocsMarkdown--example">

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

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

- **Then**:
- **Type**: _Dynamic_
- **Expression**: `concat("https://", http.host, http.request.uri.path)`

- **Target URL**: `https://${1}`
- **Status code**: _301_
- **Preserve query string**: Enabled

</div>
</div>

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

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

**How to migrate**:

1. [Create a single redirect](/rules/url-forwarding/single-redirects/create-dashboard/) to permanently redirect requests from `www.example.com` to `example.com`:
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:

<div class="DocsMarkdown--example">
<div class="DocsMarkdown--example">

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

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

- **Then**:
- **Type**: _Dynamic_
- **Expression**: `concat("https://example.com", http.request.uri.path)`

- **Target URL**: `https://example.com/${1}`
- **Status code**: _301_
- **Preserve query string**: Enabled

</div>
</div>

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

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

<Render
file="page-rules-migration-wildcard-notice"
params={{
requestUrl: "http*://www.example.com/*",
targetUrl: "https://example.com/${2}",
}}
/>

</TabItem> <TabItem label="visual guide">

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

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

<div class="DocsMarkdown--example">
<div class="DocsMarkdown--example">

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

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

- **Then**:
- **Type**: _Dynamic_
- **Expression**: `concat("/new-path/", substring(http.request.uri.path, 10))`<br/>
(where `10` (start byte value) is the length of `/old-path/`)

- **Target URL**: `https://example.com/new-path/${1}`
- **Status code**: _301_
- **Preserve query string**: Enabled

</div>
</div>

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

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

<Render
file="page-rules-migration-wildcard-notice"
params={{
requestUrl: "http*://example.com/old-path/*",
targetUrl: "https://example.com/new-path/${2}",
}}
/>

</TabItem> <TabItem label="visual guide">

| Page Rules configuration | Migrate to a single redirect |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
params:
- requestUrl
- targetUrl
---

import { Details } from "~/components";

<Details header="Notes about the rule equivalence">

The provided example using Single Redirects is not an exact match for the previously existing Page Rule in the same example.

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`):

- **Request URL**: <code>{props.requestUrl}</code>

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

- **Target URL**: <code>{props.targetUrl}</code>

</Details>

0 comments on commit 93b5b3f

Please sign in to comment.