Skip to content

Commit

Permalink
[Rules] Update formatting of Bulk Redirects (#18470)
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrosousa authored Nov 28, 2024
1 parent a6008b3 commit 8f11bd4
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ sidebar:
label: How it works
---

import { MetaInfo } from "~/components";

For each incoming request, Cloudflare evaluates all URL redirects of each Bulk Redirect List that is enabled by a Bulk Redirect Rule.

If there is a match for a URL redirect according to the URL matching algorithm, the redirect action is performed immediately, according to the URL redirect configuration parameters. Cloudflare performs no further processing once a redirect action has been executed.
Expand All @@ -14,27 +16,25 @@ If there is a match for a URL redirect according to the URL matching algorithm,

The following URL redirect parameters control the matching behavior between the request URL and source URLs of the configured (and enabled) URL redirects:

- **Subpath matching** (default: false)

- If true, the URL redirect will apply to all paths under the given source path. For example, consider the following source and target URLs of a URL redirect:
- **Subpath matching** <MetaInfo text="(default: false)"/>

— Source URL: `https://example.com/foo/`
- If `true`, the URL redirect will apply to all paths under the given source path. For example, consider the following source and target URLs of a URL redirect:

— Target URL: `https://example.com/qux/`
- Source URL: `https://example.com/foo/`
- Target URL: `https://example.com/qux/`

- With this configuration and **Subpath matching** enabled, an incoming request to `example.com/foo/bar` will be redirected to `https://example.com/qux/bar`.

:::note
URL redirects with **Subpath matching** enabled cannot contain more than 16 `/` (slash) characters in the source URL path.
:::

- **Include subdomains** (default: false)

- If true, the source URL hostname of the URL redirect will also apply to all its subdomains. For example, consider the following source and target URLs of a URL redirect:
- **Include subdomains** <MetaInfo text="(default: false)"/>

— Source URL: `https://example.com/about`
- If `true`, the source URL hostname of the URL redirect will also apply to all its subdomains. For example, consider the following source and target URLs of a URL redirect:

— Target URL: `https://example.com/newpage`
- Source URL: `https://example.com/about`
- Target URL: `https://example.com/newpage`

- With this configuration and **Includes subdomains** enabled, incoming requests to `http://a.example.com/about` and `http://a.b.example.com/about` would also match, in addition to the specified domain with no subdomain (`https://example.com/about`).

Expand All @@ -44,29 +44,27 @@ For detailed information on these parameters, refer to [URL redirect parameters]

The following parameters configure how Cloudflare determines the path and query string of the final target URL:

- **Preserve query string** (default: false)
- **Preserve query string** <MetaInfo text="(default: false)"/>

- If true, the final target URL will keep the query string of the original request. For example, consider the following source and target URLs of a URL redirect:
- If `true`, the final target URL will keep the query string of the original request. For example, consider the following source and target URLs of a URL redirect:

— Source URL: `https://example.com/about`

— Target URL: `https://example.com/newpage`
- Source URL: `https://example.com/about`
- Target URL: `https://example.com/newpage`

- With this configuration and **Preserve query string** enabled, an incoming request to `http://example.com/about?q=term` would be redirected to `https://example.com/newpage?q=term`. If **Preserve query string** is disabled, the same incoming request would be redirected to `https://example.com/newpage`.

- **Preserve path suffix** (default: true)
- **Preserve path suffix** <MetaInfo text="(default: true)"/>

- Defines if the final target URL will include the parts of the request path that did not match the URL redirect's source URL.

- When **Subpath matching** is enabled, the path that was not matched is copied over to the final target URL. For example, consider the following source and target URLs of a URL redirect:

— Source URL: `https://example.com/a/`

— Target URL: `https://example.com/b/`
- Source URL: `https://example.com/a/`
- Target URL: `https://example.com/b/`

- An incoming request to `https://example.com/a/foo` will be redirected to `https://example.com/b/foo`.

- If you set **Preserve path suffix** to false, the same request will still match the redirect, but it will be redirected to `https://example.com/b/`.
- If you set **Preserve path suffix** to `false`, the same request will still match the redirect, but it will be redirected to `https://example.com/b/`.

For detailed information on these parameters, refer to [URL redirect parameters](/rules/url-forwarding/bulk-redirects/reference/parameters/).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,54 +5,78 @@ sidebar:
order: 3
---

import { Type, MetaInfo } from "~/components";

A URL redirect has a source URL, a target URL, a status code, and some additional parameters that affect its URL matching behavior and runtime behavior.

The URL redirect parameters are the following:
## Source URL

API field: `source_url` <Type text="String" />

The URL string that the incoming request URL must match for the redirect to be applied. This property is mandatory. The maximum length of the source URL is 32 KB.

The value must be a valid URL, but the URL scheme is not required (for example, `https`); when the scheme is omitted, the redirect applies to both `http` and `https` URL schemes.

A Bulk Redirect List cannot contain several URL redirects with the exact same source URL.
The exact behavior of the [URL matching algorithm](/rules/url-forwarding/bulk-redirects/how-it-works/#url-matching-algorithm), which matches an incoming request with the redirect's source URL, depends on the values of the [**Include subdomains**](#include-subdomains) and [**Subpath matching**](#subpath-matching) parameters.

For more information on the supported URL components, refer to [Supported URL components](/rules/url-forwarding/bulk-redirects/reference/url-components/).

## Target URL

API field: `target_url` <Type text="String" />

The URL where the client will be redirected to when there is a match for the URL redirect. This property is mandatory. The maximum length of the target URL is 32 KB.

The value must be a valid URL. The final target URL depends on the values of the [**Preserve query string**](#preserve-query-string) and [**Preserve path suffix**](#preserve-path-suffix) parameters.

For more information on the supported URL components, refer to [Supported URL components](/rules/url-forwarding/bulk-redirects/reference/url-components/).

## Subpath matching

API field: `subpath_matching` <Type text="Boolean" /> <MetaInfo text="default: false" />

If `true`, the current redirect will apply the subpath matching algorithm to the request URL when determining if there is a match for the current URL redirect.

For example, a URL redirect from `/my-folder/` to `/other-folder/` with **Subpath matching** enabled will also redirect a request from `/my-folder/item` to `/other-folder/item`. However, the redirect will only include the `item` part when [**Preserve path suffix**](#preserve-path-suffix) is `true`.

For more information, refer to [Matching the source URL of redirects](/rules/url-forwarding/bulk-redirects/how-it-works/#matching-the-source-url-of-redirects).

## Include subdomains

API field: `include_subdomains` <Type text="Boolean" /> <MetaInfo text="default: false" />

If `true`, the source URL hostname will also apply to any subdomains — the redirect will match for all subdomains to the left of the domain portion of the source URL, as well as the specified domain.

For example, a redirect with source URL defined as `http://example.com/about` will also apply to requests with source URL `http://a.example.com/about` or `http://a.b.example.com/about`.

- **Source URL** (String)
For more information, refer to [Matching the source URL of redirects](/rules/url-forwarding/bulk-redirects/how-it-works/#matching-the-source-url-of-redirects).

- API field name: `source_url`.
- The URL string that the incoming request URL must match for the redirect to be applied. This property is mandatory. The maximum length of the source URL is 32 KB.
- The value must be a valid URL, but the URL scheme is not required (for example, `https`); when the scheme is omitted, the redirect applies to both `http` and `https` URL schemes.
- A Bulk Redirect List cannot contain several URL redirects with the exact same source URL.
- The exact behavior of the [URL matching algorithm](/rules/url-forwarding/bulk-redirects/how-it-works/#url-matching-algorithm), which matches an incoming request with the redirect’s source URL, depends on the values of the **Include subdomains** and **Subpath matching** parameters.
- For more information on the supported URL components, refer to [Supported URL components](/rules/url-forwarding/bulk-redirects/reference/url-components/).
## Preserve query string

- **Target URL** (String)
API field: `preserve_query_string` <Type text="Boolean" /> <MetaInfo text="default: false" />

- API field name: `target_url`.
- The URL where the client will be redirected to when there is a match for the URL redirect. This property is mandatory. The maximum length of the target URL is 32 KB.
- The value must be a valid URL. The final target URL depends on the values of the **Preserve query string** and **Preserve path suffix** parameters.
- For more information on the supported URL components, refer to [Supported URL components](/rules/url-forwarding/bulk-redirects/reference/url-components/).
If `true`, the redirect URL will keep the query string of the original request.

- **Subpath matching** (Boolean)
For example, a URL redirect from `/my-folder/` to `/other-folder/` with **Preserve query string** enabled will redirect a request from `/my-folder/?name=value` to `/other-folder/?name=value`. If **Preserve query string** is disabled, the request will be redirected from `/my-folder/?name=value` to `/other-folder/`.

- API field name: `subpath_matching`.
- If true, the current redirect will apply the subpath matching algorithm to the request URL when determining if there is a match for the current URL redirect. The default value is `false`.
- For example, a URL redirect from `/my-folder/` to `/other-folder/` with **Subpath matching** enabled will also redirect a request from `/my-folder/item` to `/other-folder/item`. However, the redirect will only include the `item` part when **Preserve path suffix** is true. Refer to **Preserve path suffix** for details.
- For more information, refer to [Matching the source URL of redirects](/rules/url-forwarding/bulk-redirects/how-it-works/#matching-the-source-url-of-redirects).
## Preserve path suffix

- **Include subdomains** (Boolean)
API field: `preserve_path_suffix` <Type text="Boolean" /> <MetaInfo text="default: true" />

- API field name: `include_subdomains`.
- If true, the source URL hostname will also apply to any subdomains — the redirect will match for all subdomains to the left of the domain portion of the source URL, as well as the specified domain. The default value is `false`.
- For example, a redirect with source URL defined as `http://example.com/about` will also apply to requests with source URL `http://a.example.com/about` or `http://a.b.example.com/about`.
- For more information, refer to [Matching the source URL of redirects](/rules/url-forwarding/bulk-redirects/how-it-works/#matching-the-source-url-of-redirects).
Applicable only when [**Subpath matching**](#subpath-matching) is enabled. If `true`, defines that the redirect URL will include the remaining (non-matched) path elements of the source URL, if any.

- <a name="preserve-query-string"></a> **Preserve query string** (Boolean)
For example, when both **Subpath matching** and **Preserve path suffix** are enabled, a URL redirect from `/my-folder/` to `/another-folder/` will redirect an incoming request from `/my-folder/foo` to `/another-folder/foo`. If **Preserve path suffix** is disabled, the same request would still match the URL redirect, but it would redirect from `/my-folder/foo` to `/another-folder/`.

- API field name: `preserve_query_string`.
- If true, the redirect URL will keep the query string of the original request. The default value is `false`.
- For example, a URL redirect from `/my-folder/` to `/other-folder/` with **Preserve query string** enabled will redirect a request from `/my-folder/?name=value` to `/other-folder/?name=value`. If **Preserve query string** is disabled, the request will be redirected from `/my-folder/?name=value` to `/other-folder/`.
## Status code

- **Preserve path suffix** (Boolean)
API field: `status_code` <Type text="Integer" /> <MetaInfo text="default: 301" />

- API field name: `preserve_path_suffix`.
- Applicable only when **Subpath matching** is enabled. If true, defines that the redirect URL will include the remaining (non-matched) path elements of the source URL, if any. The default value is `true`.
- For example, when both **Subpath matching** and **Preserve path suffix** are enabled, a URL redirect from `/my-folder/` to `/another-folder/` will redirect an incoming request from `/my-folder/foo` to `/another-folder/foo`. If **Preserve path suffix** is disabled, the same request would still match the URL redirect, but it would redirect from `/my-folder/foo` to `/another-folder/`.
The HTTP status code returned to the client when redirecting.

- **Status code** (Integer)
The value must be one of the following:

- API field name: `status_code`.
- The HTTP status code returned to the client when redirecting. The default value is `301`.
- The value must be one of the following: `301` (Moved permanently), `302` (Found, also known as Moved temporarily), `307` (Temporary redirect), or `308` (Permanent redirect).
- `301` (Moved permanently)
- `302` (Found, also known as Moved temporarily)
- `307` (Temporary redirect)
- `308` (Permanent redirect)
Loading

0 comments on commit 8f11bd4

Please sign in to comment.