New usersFree DNS and CDN plans for every new account.Create your account

Page rules

Override caching, rate limiting, response headers, origin SSL and redirects for URLs that match your conditions.

5 min read Updated Oct 6, 2026

Page rules let you handle URLs that meet certain conditions in a different way. For example, you can cache static assets for longer, turn off caching for an admin area, or redirect an old path to a new address.

Go to CDN管理 (CDN) → 域名管理 (Domains), open a domain, then select 页面规则 (Page rules). The console URL is /cdn/domains/<domain>/rules.

Note

Some page rule actions are still rolling out. This page lists only the actions that the edge currently applies. The console shows other options too, but they have no effect yet when you save them.

What a rule contains

FieldDescription
NameA label to help you identify the rule, such as "Static asset caching"
PriorityFrom 1 to 999. The default is 100
EnabledA disabled rule is kept but not applied
ConditionsOne or more conditions, joined by All match (AND) or Any match (OR)
ActionsOne or more actions to apply when a request matches

Matching URLs

Page rules use the same condition engine as firewall rules. These fields and operators are the ones most often used to describe URLs:

FieldExample
Path / URI Pathstarts with /static/; regex ^/blog/\d+
File Extensionin list jpg, png, css, js
Hostequals img.example.com (useful when a domain has several hostnames)
Query Stringparameter name utm_source, operator exists
Header / Cookiegive the name, then match its value
Is HTTPS, HTTP Method, Client IP, Country Code, ASN, User Agent, Referernarrow the match by request attributes

The available operators are equals, not equals, contains, does not contain, starts with, ends with, regex, in list, not in list, greater/less than (or equal), exists and does not exist.

Tip

Path matching is case-sensitive. To match a directory, use starts with. It's clearer than a regex and easier to get right.

Actions that take effect

Action panelSettings that applyWhat it does
缓存 (Cache)Cache mode Disabled; cache time (seconds)Disabled sends matching requests past the edge cache. A cache time replaces the edge cache TTL for cacheable responses. Responses that can't be cached, such as those with Set-Cookie or no-store, still aren't cached
限流 (Rate limit)Requests, window (seconds), key (IP address, country or URI path)Requests over the limit get 429. To rate-limit by header or cookie, use a firewall rule instead
WAFThe off switchSkips WAF inspection for matching requests, which is useful for trusted callback URLs. Selecting rule sets here has no effect
自定义头 (Custom headers)Name and valueAdds or replaces HTTP response headers
SSL/TLSOrigin SSL mode; Force HTTPS (client)Changes the SSL mode used to connect to the origin for these URLs (off, flexible, full or strict). With Force HTTPS on, HTTP requests get a 301 redirect to the same URL over HTTPS
重定向 (Redirect)Target URL and status code (301, 302, 307 or 308)Responds with a redirect to the fixed target URL without contacting the origin

These settings don't take effect yet. Configure them on the domain's own pages instead:

  • In the Cache panel: cache time mode, query string handling, cache host mode, varying by device, country or language, and serving stale content. Set these on the 缓存 (Cache) page.
  • The 浏览器缓存 (Browser cache) panel, which is still rolling out. Set browser caching on the Cache page.
  • The 优化 (Optimization) panel (Gzip, Brotli and minification). Set these on the 优化 (Optimization) page.

Create a rule

  1. On Page rules, click 添加规则 (Add rule).
  2. Enter a name, change the priority if you need to, and leave Enabled on.
  3. Under 匹配条件 (Conditions), add your conditions and choose All match or Any match.
  4. Under 执行动作 (Actions), click 启用 (Enable) on each action panel you want and fill in its settings. Click 移除 (Remove) to drop a panel.
  5. Click OK to save. The rule takes effect at the edge within seconds to a minute.

You can't save a rule unless it has at least one condition and one action.

Example: cache static assets for 7 days

  • Condition: File Extension in list jpg, png, css, js
  • Action: Cache, mode Enabled, cache time 604800

Example: don't cache the admin area

  • Condition: Path starts with /admin
  • Action: Cache, mode Disabled

When several rules match

A request can match more than one page rule, and the actions of every matching rule are applied together. A redirect or Force HTTPS ends processing immediately, so no further rules run.

Warning

Don't give the same URLs conflicting values in different rules, such as two different cache times. Keep conditions from overlapping, or combine those rules into one.

Rule quota

Your plan may limit how many page rules you can create. If it does, a banner at the top of the page shows your usage, such as "规则配额:3/5". When you reach the limit, delete rules you no longer need or upgrade your plan.

API

The page rule endpoints are under /api/user/cdn/rules:

bash
curl -X POST "https://api.yeap.cloud/api/user/cdn/rules/create" \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '{
    "domain_id": 123,
    "name": "Static assets 7d",
    "priority": 100,
    "enabled": true,
    "settings": {
      "matcher": {"op": "and", "conditions": [
        {"collection": "EXTENSION", "op": "in", "var": ["jpg", "png", "css", "js"]}
      ]},
      "action": {"cache": {"enabled": "on", "ttl": 604800}}
    }
  }'

Other endpoints:

  • List rules: GET /api/user/cdn/rules?domain_id=123
  • Update a rule: POST /api/user/cdn/rules/update, with id in the body
  • Delete a rule: DELETE /api/user/cdn/rules/delete?id=<id>
Was this page helpful?