Skip to content

Commit 79b3232

Browse files
authored
[Rules] Add two Origin Rules tutorials (#21627)
* [Rules] Convert example into a tutorial * Move two API examples to partials * FAQ: Small formatting updates * Add missing partials (fix previous commit) * Change page order * Add two tutorials (origin rules and Pages / R2 with custom domain) * Unhide tutorials list * Fix broken links
1 parent 0f6e9d2 commit 79b3232

15 files changed

+575
-243
lines changed

public/__redirects

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,7 @@
998998
/rules/transform/manage/ /rules/transform/ 301
999999
/rules/page-rules/how-to/rewrite-host-headers/ /rules/origin-rules/examples/change-uri-path-and-host-header/ 301
10001000
/rules/page-rules/how-to/override-url-or-ip-address/ /rules/origin-rules/features/ 301
1001+
/rules/origin-rules/examples/change-uri-path-and-host-header/ /rules/origin-rules/tutorials/change-uri-path-and-host-header/ 301
10011002

10021003
# ruleset engine
10031004
/ruleset-engine/rules-language/fields/standard-fields/ /ruleset-engine/rules-language/fields/reference/ 301

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

Lines changed: 5 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -33,55 +33,13 @@ Make sure your API token has the [required permissions](#required-api-token-perm
3333

3434
<Details header="Example: Add a rule that overrides the HTTP `Host` header">
3535

36-
The following example sets the rules of an existing phase ruleset (`$RULESET_ID`) to a single origin rule — overriding the HTTP `Host` header — using the [Update a zone ruleset](/api/resources/rulesets/methods/update/) operation. The response will contain the complete definition of the ruleset you updated.
36+
<Render file="origin-rules-api-change-host-header" />
3737

38-
<APIRequest
39-
path="/zones/{zone_id}/rulesets/{ruleset_id}"
40-
method="PUT"
41-
json={{
42-
rules: [
43-
{
44-
expression: 'http.request.uri.query contains "/eu/"',
45-
description: "My first origin rule",
46-
action: "route",
47-
action_parameters: {
48-
host_header: "eu_server.example.net",
49-
},
50-
},
51-
],
52-
}}
53-
/>
38+
</Details>
5439

55-
```json output
56-
{
57-
"result": {
58-
"id": "<RULESET_ID>",
59-
"name": "Origin Rules ruleset",
60-
"description": "Zone-level ruleset that will execute origin rules.",
61-
"kind": "zone",
62-
"version": "2",
63-
"rules": [
64-
{
65-
"id": "<RULE_ID>",
66-
"version": "1",
67-
"action": "route",
68-
"action_parameters": {
69-
"host_header": "eu_server.example.net"
70-
},
71-
"expression": "http.request.uri.query contains \"/eu/\"",
72-
"description": "My first origin rule",
73-
"last_updated": "2022-06-02T14:42:04.219025Z",
74-
"ref": "<RULE_REF>"
75-
}
76-
],
77-
"last_updated": "2022-06-02T14:42:04.219025Z",
78-
"phase": "http_request_origin"
79-
},
80-
"success": true,
81-
"errors": [],
82-
"messages": []
83-
}
84-
```
40+
<Details header="Example: Add a rule that overrides the port of incoming requests">
41+
42+
<Render file="origin-rules-api-change-port" />
8543

8644
</Details>
8745

@@ -170,64 +128,6 @@ The following example sets the rules of an existing phase ruleset (`$RULESET_ID`
170128

171129
</Details>
172130

173-
<Details header="Example: Add a rule that overrides the port of incoming requests">
174-
175-
The following example sets the rules of an existing phase ruleset (`$RULESET_ID`) to a single origin rule — overriding the port 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.
176-
177-
<APIRequest
178-
path="/zones/{zone_id}/rulesets/{ruleset_id}"
179-
method="PUT"
180-
json={{
181-
rules: [
182-
{
183-
expression: 'starts_with(http.request.uri.path, "/team/calendar/")',
184-
description: "Origin rule for the team calendar application",
185-
action: "route",
186-
action_parameters: {
187-
origin: {
188-
port: 9000,
189-
},
190-
},
191-
},
192-
],
193-
}}
194-
/>
195-
196-
```json output
197-
{
198-
"result": {
199-
"id": "<RULESET_ID>",
200-
"name": "Origin Rules ruleset",
201-
"description": "Zone-level ruleset that will execute origin rules.",
202-
"kind": "zone",
203-
"version": "2",
204-
"rules": [
205-
{
206-
"id": "<RULE_ID>",
207-
"version": "1",
208-
"action": "route",
209-
"action_parameters": {
210-
"origin": {
211-
"port": 9000
212-
}
213-
},
214-
"expression": "starts_with(http.request.uri.path, \"/team/calendar/\")",
215-
"description": "Origin rule for the team calendar application",
216-
"last_updated": "2022-06-03T14:42:04.219025Z",
217-
"ref": "<RULE_REF>"
218-
}
219-
],
220-
"last_updated": "2022-06-03T14:42:04.219025Z",
221-
"phase": "http_request_origin"
222-
},
223-
"success": true,
224-
"errors": [],
225-
"messages": []
226-
}
227-
```
228-
229-
</Details>
230-
231131
---
232132

233133
## Required API token permissions
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
pcx_content_type: example
3+
summary: Create an origin rule to change the HTTP `Host` header.
4+
products:
5+
- Origin Rules
6+
title: Change the HTTP Host header
7+
description: Create an origin rule to change the HTTP `Host` header.
8+
---
9+
10+
import { Render, Tabs, TabItem, Example } from "~/components";
11+
12+
The following origin rule overrides the HTTP `Host` header to `eu_server.example.net` for all requests containing `/eu/` in their URI path.
13+
14+
<Tabs syncKey="dashPlusAPI">
15+
<TabItem label="Dashboard" no-code="true">
16+
17+
<Example>
18+
19+
Text in Expression Editor:
20+
21+
```txt
22+
http.request.uri.path contains "/eu/"
23+
```
24+
25+
Value after **Host Header** > **Rewrite to**:
26+
27+
```txt
28+
eu_server.example.net
29+
```
30+
31+
</Example>
32+
33+
</TabItem>
34+
<TabItem label="API" no-code="true">
35+
36+
<Render file="origin-rules-api-change-host-header" />
37+
38+
</TabItem>
39+
</Tabs>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
pcx_content_type: example
3+
summary: Create an origin rule to change the destination port.
4+
products:
5+
- Origin Rules
6+
title: Change the destination port
7+
description: Create an origin rule to change the destination port.
8+
---
9+
10+
import { Render, Tabs, TabItem, Example } from "~/components";
11+
12+
The following origin rule overrides the destination port to `8081` for all requests where the URI path starts with `/team/calendar/`.
13+
14+
<Tabs syncKey="dashPlusAPI">
15+
<TabItem label="Dashboard" no-code="true">
16+
17+
<Example>
18+
19+
Text in Expression Editor:
20+
21+
```txt
22+
starts_with(http.request.uri.path, "/team/calendar/")
23+
```
24+
25+
Value after **Destination Port** > **Rewrite to**:
26+
27+
```txt
28+
8081
29+
```
30+
31+
</Example>
32+
33+
</TabItem>
34+
<TabItem label="API" no-code="true">
35+
36+
<Render file="origin-rules-api-change-port" />
37+
38+
</TabItem>
39+
</Tabs>

src/content/docs/rules/origin-rules/examples/change-uri-path-and-host-header.mdx

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

src/content/docs/rules/origin-rules/examples/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ type: overview
33
pcx_content_type: navigation
44
title: Examples
55
sidebar:
6-
order: 10
6+
order: 5
77
---
88

99
import { ListExamples } from "~/components";

0 commit comments

Comments
 (0)