Skip to content

PageRule

Source: src/Cloudflare/PageRule/PageRule.ts

A Cloudflare Page Rule — a legacy zone-level rule that matches a URL pattern (target) and applies a set of actions (cache settings, SSL mode, redirects, etc.) at a given priority.

A rule’s recoverable identity is its target URL pattern within the zone. Page Rules carry no ownership markers, so when there is no prior state read scans the zone for a rule with the same target and reports it as Unowned — the engine refuses to take it over unless --adopt (or adopt(true)) is set.

yield* Cloudflare.PageRule.PageRule("CacheImages", {
zoneId: zone.zoneId,
target: `${zone.name}/images/*`,
actions: [
{ id: "cache_level", value: "cache_everything" },
{ id: "edge_cache_ttl", value: 7200 },
],
});
// forwarding_url cannot be combined with most other actions.
yield* Cloudflare.PageRule.PageRule("RedirectOldBlog", {
zoneId: zone.zoneId,
target: `${zone.name}/blog/*`,
actions: [
{
id: "forwarding_url",
value: { url: "https://new.example.com/blog/$1", statusCode: "301" },
},
],
});
yield* Cloudflare.PageRule.PageRule("SecureAdmin", {
zoneId: zone.zoneId,
target: `${zone.name}/admin/*`,
actions: [
{ id: "always_use_https" },
{ id: "security_level", value: "high" },
],
priority: 2,
});
yield* Cloudflare.PageRule.PageRule("BypassCacheBeta", {
zoneId: zone.zoneId,
target: `${zone.name}/beta/*`,
actions: [{ id: "cache_level", value: "bypass" }],
status: "disabled",
});