-
Notifications
You must be signed in to change notification settings - Fork 10k
[Rules] Update Origin Rules #22659
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
pedrosousa
merged 5 commits into
production
from
pedro/PCX-17296-rules-update-origin-rules
May 27, 2025
Merged
[Rules] Update Origin Rules #22659
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 22 additions & 8 deletions
30
src/content/docs/rules/origin-rules/examples/change-http-host-header.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,39 +1,53 @@ | ||
| --- | ||
| pcx_content_type: example | ||
| summary: Create an origin rule to change the HTTP `Host` header. | ||
| summary: Create an origin rule to change the HTTP `Host` header and DNS record. | ||
| products: | ||
| - Origin Rules | ||
| title: Change the HTTP Host header | ||
| description: Create an origin rule to change the HTTP `Host` header. | ||
| title: Change the HTTP Host header and DNS record | ||
| description: Create an origin rule to change the HTTP `Host` header and the resolved DNS record. | ||
| --- | ||
|
|
||
| import { Render, Tabs, TabItem, Example } from "~/components"; | ||
|
|
||
| The following origin rule overrides the HTTP `Host` header to `eu_server.example.net` for all requests containing `/eu/` in their URI path. | ||
| 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. | ||
|
|
||
| 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/). | ||
|
|
||
| <Tabs syncKey="dashPlusAPI"> | ||
| <TabItem label="Dashboard" no-code="true"> | ||
|
|
||
| <Example> | ||
|
|
||
| Text in Expression Editor: | ||
| Expression when using the Expression Builder: | ||
|
|
||
| | Field | Operator | Value | | ||
| | -------- | ----------- | ---------- | | ||
| | URI Path | starts with | `/hr-app/` | | ||
|
|
||
| Expression when using the Expression Editor: | ||
|
|
||
| ```txt | ||
| http.request.uri.path contains "/eu/" | ||
| (starts_with(http.request.uri.path, "/hr-app/")) | ||
| ``` | ||
|
|
||
| Value after **Host Header** > **Rewrite to**: | ||
|
|
||
| ```txt | ||
| eu_server.example.net | ||
| hr-server.example.com | ||
| ``` | ||
|
|
||
| Value after **DNS Record** > **Override to**: | ||
|
|
||
| ```txt | ||
| hr-server.example.com | ||
| ``` | ||
|
|
||
| </Example> | ||
|
|
||
| </TabItem> | ||
| <TabItem label="API" no-code="true"> | ||
|
|
||
| <Render file="origin-rules-api-change-host-header" /> | ||
| <Render file="origin-rules-api-change-host-header-dns-record" /> | ||
|
|
||
| </TabItem> | ||
| </Tabs> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/content/partials/rules/origin-rules-api-change-host-header-dns-record.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| --- | ||
| {} | ||
| --- | ||
|
|
||
| import { APIRequest } from "~/components"; | ||
|
|
||
| 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. | ||
|
|
||
| <APIRequest | ||
| path="/zones/{zone_id}/rulesets/{ruleset_id}" | ||
| method="PUT" | ||
| json={{ | ||
| rules: [ | ||
| { | ||
| expression: 'starts_with(http.request.uri.path, "/hr-app/")', | ||
| description: "Origin rule for the company HR application", | ||
| action: "route", | ||
| action_parameters: { | ||
| host_header: "hr-server.example.com", | ||
| origin: { | ||
| host: "hr-server.example.com", | ||
| }, | ||
| }, | ||
| }, | ||
| ], | ||
| }} | ||
| /> | ||
|
|
||
| ```json output | ||
| { | ||
| "result": { | ||
| "id": "<RULESET_ID>", | ||
| "name": "Origin Rules ruleset", | ||
| "description": "Zone-level ruleset that will execute origin rules.", | ||
| "kind": "zone", | ||
| "version": "2", | ||
| "rules": [ | ||
| { | ||
| "id": "<RULE_ID>", | ||
| "version": "1", | ||
| "action": "route", | ||
| "action_parameters": { | ||
| "host_header": "hr-server.example.com", | ||
| "origin": { | ||
| "host": "hr-server.example.com" | ||
| } | ||
| }, | ||
| "expression": "starts_with(http.request.uri.path, \"/hr-app/\")", | ||
| "description": "Origin rule for the company HR application", | ||
| "last_updated": "2022-06-03T14:42:04.219025Z", | ||
| "ref": "<RULE_REF>" | ||
| } | ||
| ], | ||
| "last_updated": "2022-06-03T14:42:04.219025Z", | ||
| "phase": "http_request_origin" | ||
| }, | ||
| "success": true, | ||
| "errors": [], | ||
| "messages": [] | ||
| } | ||
| ``` |
55 changes: 0 additions & 55 deletions
55
src/content/partials/rules/origin-rules-api-change-host-header.mdx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.