Skip to content

Commit 3354bf9

Browse files
authored
[Rules] Update Origin Rules (#22659)
1 parent a1518ee commit 3354bf9

File tree

6 files changed

+95
-131
lines changed

6 files changed

+95
-131
lines changed

src/content/docs/rules/origin-rules/create-api.mdx

Lines changed: 2 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ Make sure your API token has the [required permissions](#required-api-token-perm
2929

3030
## Example requests
3131

32-
<Details header="Example: Add a rule that overrides the HTTP `Host` header">
32+
<Details header="Example: Add a rule that overrides the `Host` header of incoming requests and the resolved DNS record">
3333

34-
<Render file="origin-rules-api-change-host-header" />
34+
<Render file="origin-rules-api-change-host-header-dns-record" />
3535

3636
</Details>
3737

@@ -66,66 +66,6 @@ The following example sets the rules of an existing phase ruleset (`$RULESET_ID`
6666

6767
</Details>
6868

69-
<Details header="Example: Add a rule that overrides the resolved DNS record and the `Host` header of incoming requests">
70-
71-
The following example sets the rules of an existing phase ruleset (`$RULESET_ID`) to a single origin rule — overriding the resolved DNS record and the `Host` header of incoming requests — using the [Update a zone ruleset](/api/resources/rulesets/methods/update/) operation. The response will contain the complete definition of the ruleset you updated.
72-
73-
<APIRequest
74-
path="/zones/{zone_id}/rulesets/{ruleset_id}"
75-
method="PUT"
76-
json={{
77-
rules: [
78-
{
79-
expression: 'starts_with(http.request.uri.path, "/hr-app/")',
80-
description: "Origin rule for the company HR application",
81-
action: "route",
82-
action_parameters: {
83-
host_header: "hr-server.example.com",
84-
origin: {
85-
host: "hr-server.example.com",
86-
},
87-
},
88-
},
89-
],
90-
}}
91-
/>
92-
93-
```json output
94-
{
95-
"result": {
96-
"id": "<RULESET_ID>",
97-
"name": "Origin Rules ruleset",
98-
"description": "Zone-level ruleset that will execute origin rules.",
99-
"kind": "zone",
100-
"version": "2",
101-
"rules": [
102-
{
103-
"id": "<RULE_ID>",
104-
"version": "1",
105-
"action": "route",
106-
"action_parameters": {
107-
"host_header": "hr-server.example.com",
108-
"origin": {
109-
"host": "hr-server.example.com"
110-
}
111-
},
112-
"expression": "starts_with(http.request.uri.path, \"/hr-app/\")",
113-
"description": "Origin rule for the company HR application",
114-
"last_updated": "2022-06-03T14:42:04.219025Z",
115-
"ref": "<RULE_REF>"
116-
}
117-
],
118-
"last_updated": "2022-06-03T14:42:04.219025Z",
119-
"phase": "http_request_origin"
120-
},
121-
"success": true,
122-
"errors": [],
123-
"messages": []
124-
}
125-
```
126-
127-
</Details>
128-
12969
---
13070

13171
## Required API token permissions
Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,53 @@
11
---
22
pcx_content_type: example
3-
summary: Create an origin rule to change the HTTP `Host` header.
3+
summary: Create an origin rule to change the HTTP `Host` header and DNS record.
44
products:
55
- Origin Rules
6-
title: Change the HTTP Host header
7-
description: Create an origin rule to change the HTTP `Host` header.
6+
title: Change the HTTP Host header and DNS record
7+
description: Create an origin rule to change the HTTP `Host` header and the resolved DNS record.
88
---
99

1010
import { Render, Tabs, TabItem, Example } from "~/components";
1111

12-
The following origin rule overrides the HTTP `Host` header to `eu_server.example.net` for all requests containing `/eu/` in their URI path.
12+
The following origin rule overrides the HTTP `Host` header to `hr-server.example.com` for all requests with a URI path starting with `/hr-app/`. It also overrides the DNS record to the same hostname.
13+
14+
The `Host` header override only updates the header value; the DNS record override will handle the rerouting of incoming requests. For more information on these overrides, refer to [Available settings](/rules/origin-rules/features/).
1315

1416
<Tabs syncKey="dashPlusAPI">
1517
<TabItem label="Dashboard" no-code="true">
1618

1719
<Example>
1820

19-
Text in Expression Editor:
21+
Expression when using the Expression Builder:
22+
23+
| Field | Operator | Value |
24+
| -------- | ----------- | ---------- |
25+
| URI Path | starts with | `/hr-app/` |
26+
27+
Expression when using the Expression Editor:
2028

2129
```txt
22-
http.request.uri.path contains "/eu/"
30+
(starts_with(http.request.uri.path, "/hr-app/"))
2331
```
2432

2533
Value after **Host Header** > **Rewrite to**:
2634

2735
```txt
28-
eu_server.example.net
36+
hr-server.example.com
37+
```
38+
39+
Value after **DNS Record** > **Override to**:
40+
41+
```txt
42+
hr-server.example.com
2943
```
3044

3145
</Example>
3246

3347
</TabItem>
3448
<TabItem label="API" no-code="true">
3549

36-
<Render file="origin-rules-api-change-host-header" />
50+
<Render file="origin-rules-api-change-host-header-dns-record" />
3751

3852
</TabItem>
3953
</Tabs>

src/content/docs/rules/origin-rules/features.mdx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ A common use case for this functionality is when your content is hosted on a thi
2020

2121
:::note[Notes]
2222

23-
- An origin rule performing a Host header override will also update the Server Name Indication (SNI) value of the original request to the same value. To set an SNI value different from the Host header value, add an [SNI override](#server-name-indication-sni) in the same origin rule or create a separate origin rule for this purpose.
23+
- In most situations, when you rewrite the HTTP `Host` header you also need to configure a [DNS record override](#dns-record). The `Host` header override only updates the header value; the DNS record override will handle the rerouting of the request.
24+
25+
- An origin rule performing a `Host` header override will also update the Server Name Indication (SNI) value of the original request to the same value. To set an SNI value different from the `Host` header value, add an [SNI override](#server-name-indication-sni) in the same origin rule or create a separate origin rule for this purpose.
2426

2527
- If you have configured load balancing through Cloudflare and you wish to override the HTTP `Host` header per origin or for a given monitor, refer to [Override HTTP Host headers](/load-balancing/additional-options/override-http-host-headers/) in the Load Balancing documentation for more information.
2628

@@ -30,10 +32,9 @@ A common use case for this functionality is when your content is hosted on a thi
3032

3133
Allows you to override the Server Name Indication (SNI) [^1] value of a request. For more information, refer to [What is SNI (Server Name Indication)?](https://www.cloudflare.com/learning/ssl/what-is-sni/) in the Learning Center.
3234

33-
The new SNI value must be a valid hostname on the same Cloudflare account (possibly on a different zone).
34-
3535
:::note[Notes]
3636

37+
- The new SNI value must be a valid hostname on the same Cloudflare account (possibly on a different zone).
3738
- Currently, you can only use a static value when overriding SNI.
3839
- An SNI override will take precedence over [SNI rewrites of custom origins](/cloudflare-for-platforms/cloudflare-for-saas/start/advanced-settings/custom-origin/#sni-rewrites) when using Cloudflare for SaaS.
3940

@@ -47,9 +48,13 @@ Allows you to override the resolved hostname of incoming requests. This function
4748

4849
A common use case is when you are serving an application from the URI (for example, `mydomain.com/app`). In this case, the `app` may be hosted on a different server or by a third party. A DNS record override allows you to redirect requests to this endpoint to the server for that third-party application.
4950

50-
You must specify a valid hostname in a DNS record override that is a hostname on the same Cloudflare account (possibly on a different zone).
51+
:::note
52+
53+
- You must specify a valid hostname in a DNS record override that is a hostname on the same Cloudflare account (possibly on a different zone). You can [configure a DNS record](/dns/manage-dns-records/how-to/create-dns-records#create-dns-records) (a `CNAME`, `A`, or `AAAA` record) with a hostname pointing to a third-party hostname/IP address, either proxied by Cloudflare or not.
5154

52-
You can [configure a DNS record](/dns/manage-dns-records/how-to/create-dns-records#create-dns-records) (a `CNAME`, `A`, or `AAAA` record) with a hostname pointing to a third-party hostname/IP address, either proxied by Cloudflare or not.
55+
- In most situations, when you configure a DNS record override you also need to configure a [`Host` header override](#host-header). The DNS record override handles the rerouting of the request; the `Host` header override updates the `Host` HTTP header value in the request. Defining a `Host` header override will also update the Server Name Indication (SNI) value of the original request to the same value. To set an SNI value different from the `Host` header value, add an [SNI override](#server-name-indication-sni) in the same origin rule or create a separate origin rule for this purpose.
56+
57+
:::
5358

5459
The following example DNS records configure a `resolve.example.com` hostname pointing to an external hostname and IP address using a `CNAME` record and an `A` record, respectively:
5560

src/content/docs/rules/origin-rules/parameters.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ Create [different overrides](/rules/origin-rules/features/) by including differe
1717
| DNS record override / Destination port override | [`origin` object](#dns-record-override-and-destination-port-override-parameters) |
1818

1919
:::note
20-
2120
The same origin rule can have different types of overrides. Refer to [Configuring several overrides in the same rule](#configuring-several-overrides-in-the-same-rule) for a syntax example.
2221
:::
2322

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
{}
3+
---
4+
5+
import { APIRequest } from "~/components";
6+
7+
The following example sets the rules of an existing phase ruleset (`$RULESET_ID`) to a single origin rule — overriding the `Host` header of incoming requests and the resolved DNS record — using the [Update a zone ruleset](/api/resources/rulesets/methods/update/) operation. The response will contain the complete definition of the ruleset you updated.
8+
9+
<APIRequest
10+
path="/zones/{zone_id}/rulesets/{ruleset_id}"
11+
method="PUT"
12+
json={{
13+
rules: [
14+
{
15+
expression: 'starts_with(http.request.uri.path, "/hr-app/")',
16+
description: "Origin rule for the company HR application",
17+
action: "route",
18+
action_parameters: {
19+
host_header: "hr-server.example.com",
20+
origin: {
21+
host: "hr-server.example.com",
22+
},
23+
},
24+
},
25+
],
26+
}}
27+
/>
28+
29+
```json output
30+
{
31+
"result": {
32+
"id": "<RULESET_ID>",
33+
"name": "Origin Rules ruleset",
34+
"description": "Zone-level ruleset that will execute origin rules.",
35+
"kind": "zone",
36+
"version": "2",
37+
"rules": [
38+
{
39+
"id": "<RULE_ID>",
40+
"version": "1",
41+
"action": "route",
42+
"action_parameters": {
43+
"host_header": "hr-server.example.com",
44+
"origin": {
45+
"host": "hr-server.example.com"
46+
}
47+
},
48+
"expression": "starts_with(http.request.uri.path, \"/hr-app/\")",
49+
"description": "Origin rule for the company HR application",
50+
"last_updated": "2022-06-03T14:42:04.219025Z",
51+
"ref": "<RULE_REF>"
52+
}
53+
],
54+
"last_updated": "2022-06-03T14:42:04.219025Z",
55+
"phase": "http_request_origin"
56+
},
57+
"success": true,
58+
"errors": [],
59+
"messages": []
60+
}
61+
```

src/content/partials/rules/origin-rules-api-change-host-header.mdx

Lines changed: 0 additions & 55 deletions
This file was deleted.

0 commit comments

Comments
 (0)