Loading...

CDN.com.tr Help

Write a rule for a domain and path

On the Rules tab of Domains & Rules, a rule picks requests by domain, protocol and path, then sets how they are cached, which headers are added or removed, where they are fetched from and who may open them.

Write a rule for a domain and path

On the Rules tab of Domains & Rules, a rule picks requests by domain, protocol and path, then sets how they are cached, which headers are added or removed, where they are fetched from and who may open them.

Panel path

  1. Management Panel
  2. CDN Accounts
  3. Domains & Rules
  4. Rules
  5. Add rule
  6. Save rule

What does a rule solve?

These examples use safe WordPress-origin scenarios for static files, query strings, headers/cookies, and sensitive session paths.

Static asset cache

Cache CSS/JS aggressively

Cache static files for a day or longer with Cache for a fixed time, and leave campaign tracking parameters out of the cache key.

Pull / Push / Hosting Default, CNAME, or Full DNS
WordPress session

Bypass admin, login, cart, and checkout

Choose Don't cache this path for wp-admin and wp-login; on cached paths, skip the cache when a session or cart cookie is present.

WordPress platform Custom domain
Header hygiene

Clean origin headers and debug safely

Have the edge ignore Set-Cookie or Cache-Control from your origin when it caches, remove X-Origin-Debug/X-Powered-By before responses reach browsers, and switch on Debug headers only while testing.

Pull CDN Every delivery method
Expensive endpoint

Rate-limit and allow-list query params

For API-like paths, keep only the query parameters that change the content in the cache key, and set a limit of requests per visitor IP.

Dynamic origin Default, CNAME, or Full DNS
Different origin folder

Serve a path from another folder on the origin

In the Origin row, choose Fetch from a folder on the origin and enter, for example, /wp-content/site-root/apple/: requests matching this rule are fetched from that folder on the origin. The visitor's address does not change; the cache key and the purge path stay the visitor's path. Only for Starts with paths.

Pull / Hosting Any delivery method

Prerequisites

  • An account must be selected, and the domain must be added on the Domains tab.
  • Saving a rule publishes it to the edge; review the domains, the path and which rule handles the request first.
  • Screenshots use values such as www.example.com instead of real customer domains.
  • For session-based apps such as WordPress, write admin/login/cart bypass rules before caching broadly.

Decision model

Scope first

Narrow the rule by domain, protocol and path before changing behavior; a rule for All paths needs deliberate review.

  • Domains: which domains does the rule cover?
  • Protocol: HTTP, HTTPS or both?
  • Path: All paths, Starts with, Is exactly, File type is, or Regular expression (advanced)?

Cache key query model

Keep query parameters in the cache key only when they change the content; tracking parameters usually get removed.

  • Use the whole query string: every parameter makes a separate cached copy.
  • Ignore all query strings or Ignore these parameters: collapses campaign parameters.
  • Use only these parameters: keeps only parameters such as lang or v.

Bypass or TTL?

Personalized, cart, and admin content should bypass cache; static and anonymous content can receive TTL.

  • Don't cache this path: session, admin and cart paths.
  • Cache for a fixed time: static and anonymous content.
  • Cached status codes (More cache options): a separate time for 404, 500 and other status codes.

Header and cookie behavior

Ignoring an origin header for cache decisions is different from hiding it from the client.

  • Origin headers the edge ignores (More cache options): headers that should not affect caching.
  • Remove headers (Headers row): headers browsers should not see.
  • Skip the cache when these cookies are present (More cache options): skip the cache when the cookie is present.

Step-by-step guide

1

Open the rule editor

The Optimization, Caching and Security tabs set account-wide behavior; a rule sets precise behavior for some domains and paths.

  • Select the target account from CDN Accounts.
  • Open Domains & Rules and go to the Rules tab.
  • Press Add rule.

Expected result: The New rule editor opens within the selected account.

cdnctl equivalent
cdnctl accounts list
export ACCOUNT_UUID=<selected_account_uuid>
2

Narrow the domains, protocol and path

These fields decide which requests the rule matches; an overly broad regex can change the whole site.

  • Under When a request matches, tick the domains in Domains.
  • Under Protocol, choose HTTP, HTTPS or both.
  • Under Path, choose Starts with, Is exactly, File type is or Regular expression (advanced), and enter the path.
  • Choose an Application preset in the Caching row if one fits.
  • If the content sits in a different folder on the origin, choose Fetch from a folder on the origin in the Origin row; it is offered for Starts with paths only.

Expected result: The rule matches only the target hostname and paths.

cdnctl equivalent
cat > rule-static-assets.json <<EOF
{"server_domain_names":["www.example.com"],"type":["http","http2"],"path_regex":"^/cdn-help/rules/(cache-demo\\.css|query-demo\\.json)$"}
EOF
3

Set the cache time, cache key and status codes

For static files, remove tracking query parameters from the cache key and keep only real variants.

  • In the Caching row, choose Cache for a fixed time and enter the time.
  • Under Query string in the cache key, choose Ignore these parameters or Use only these parameters.
  • Open More cache options to give status codes their own time under Cached status codes, or to cache POST requests too.

Expected result: Anonymous CSS/JSON objects are cached without splitting cache by unnecessary query parameters.

cdnctl equivalent
jq '. + {"cache_query_mode":"ignore_list","cache_query_params":["utm_*","gclid","fbclid","msclkid"],"cache_valid_time":"1 day","allowed_cache_methods":["GET","HEAD"],"allowed_cache_responses":["200","301","302","304"],"response_cache_times":{"200":"1 day","301":"1 week","302":"2 hours","304":"1 day"}}' rule-static-assets.json > rule-static-assets-cache.json
4

Keep WordPress session paths out of cache

Admin, login, cart, and checkout paths should preserve origin behavior instead of returning cache hits.

  • Choose Starts with or Regular expression (advanced) for the /wp-admin, wp-login.php, cart or checkout paths.
  • In the Caching row, choose Don't cache this path.
  • On paths that stay cached, enter the session and cart cookies one per line under More cache options → Skip the cache when these cookies are present.
  • Set Requests per visitor IP or Hotlink protection if needed.

Expected result: Session requests do not return shared cached content to another user.

cdnctl equivalent
cat > rule-wordpress-sensitive.json <<EOF
{"server_domain_names":["www.example.com"],"type":["http","http2"],"path_regex":"^/(wp-admin|wp-login\\.php|cart|checkout)(/.*)?$","bypass":"on","bypass_by_cookie":"wordpress_logged_in\nwoocommerce_cart_hash\nwp_woocommerce_session_","limit":30,"per_time":10}
EOF
5

Headers, optimization and debug

Decide separately whether origin headers affect cache decisions and whether they are exposed to browsers.

  • Under More cache options, use Origin headers the edge ignores for headers that should not affect caching.
  • In the Headers row, use Remove headers for headers browsers should not see.
  • Use Add response headers to add your own headers, one per line.
  • Switch on Debug headers only while testing.
  • Try image optimization on a narrow path first (Image optimization row).

Expected result: Origin headers are controlled deliberately and debug is not left enabled in production traffic.

cdnctl equivalent
jq '. + {"ignore_headers":["Cache-Control","Set-Cookie"],"hide_headers":["X-Origin-Debug","X-Powered-By"],"custom_headers":"X-CDN-Rule-Debug temporary","debug_upstream_headers":true,"image_optimization":"on"}' rule-static-assets-cache.json > rule-headers-debug.json
6

Save, wait for publishing and check the public URL

Saving a rule publishes it to the edge, so the final check is done on the public URL: path, domain, cache time and headers.

  • Before saving, check the domains and the path, and use Test a URL on the Rules tab to see which rule handles it.
  • Press Save rule; the editor says so while the change is still being published to the edge.
  • Test status, cache headers, removed headers and cookie bypass on the public URL.

Expected result: After operation success, matching requests show the new cache/header/rate-limit behavior.

cdnctl equivalent
cdnctl cdn advanced-rules validate --account "$ACCOUNT_UUID" --file rule-headers-debug.json
cdnctl cdn advanced-rules create --account "$ACCOUNT_UUID" --file rule-headers-debug.json
# Both commands post the same JSON; create writes it via /api/advanced_managements/{account_uuid}/store.
curl -I "https://www.example.com/cdn-help/rules/cache-demo.css?utm_source=test"
curl -I -H "Cookie: wordpress_logged_in=redacted" "https://www.example.com/wp-admin/"

Verification

  • The domains, the path and the changed rows are reviewed, and Test a URL shows the expected rule.
  • Rules for All paths or a broad regular expression are reviewed deliberately.
  • Debug headers are turned off after testing.
  • After publishing, the public URL, status code, cache-key query behavior and header/cookie result are verified with curl or browser devtools.
  • cdnctl cdn advanced-rules validate checks the same JSON without saving it, and cdnctl cdn advanced-rules create writes it through /api/advanced_managements/{account_uuid}/store; a pipeline without cdnctl can post the JSON to that API directly.

Use cases

WordPress admin/cart bypasses cache while static assets and anonymous JSON paths are cached deliberately.

Quick workflow

  1. Open Domains & Rules and go to the Rules tab.
  2. Press Add rule, or Edit on the rule you want to change.
  3. Under When a request matches, choose the domains, the protocol and the path.
  4. Under Then, set Caching and, when needed, Headers, Origin and the access rows; press Save rule and check the public URL.

Checks

  • Each request is handled by exactly one rule; Test a URL on the Rules tab shows which one, and why.
  • The path is no wider than needed: prefer Starts with or Is exactly to Regular expression (advanced).
  • Debug headers are switched off after testing.
  • The editor lists what to fix before it saves.

Related pages

Block traffic by ASN and by country

Two account-wide blacklists on the same panel: block whole countries by country code, or block whole networks by autonomous system number. A blocked visitor gets the branded 403 page with a Reference ID.

Restrict a path with a password or an IP allow list

Close a staging site, an admin area or a private folder at the edge: on a delivery rule, ask for a username and password, let only the IP addresses you list through, or both. Requests that do not pass are answered by the edge and never reach your server.

Turn on HSTS for your hostnames

The Always HTTPS (HSTS) switch makes the edge send Strict-Transport-Security: max-age=31536000 on HTTPS responses, so a browser that has seen your site once refuses to open it over plain HTTP for a year.

Read WAF logs

Use WAF logs to see which requests were blocked or challenged, and why.

WAF log-only mode: try the rules before they block

Put the WAF in log-only mode for the whole site or for the paths you choose, for 7, 14 or 30 days. The WAF rules keep inspecting every request and write the ones they would have blocked to the logs as "would have been blocked", but block none of them. When the period ends, the account goes back to blocking by itself.

Purge cached content

Purge a path, saved path, or the whole account and separate CDN cache from browser cache.

Signed URLs: links that expire

Protect a file so it can only be fetched with a signature you generate, valid until a moment you choose. Unsigned requests get 403, expired ones get 410.

Image optimization: AVIF and WebP at the edge

Switch on image optimization for the account or for one delivery rule and choose WebP or WebP + AVIF: the edge converts JPEG and PNG images and sends each browser a format it accepts, while your pages keep the same image URLs.

Redirect a domain to another domain (301)

Send requests for a domain to another domain with a permanent (301) redirect from the Redirects tab of Domains & Rules. The path and query string are kept, and Auto SSL certificate checks under /.well-known keep working.

Brotli and gzip compression

The edge compresses text responses automatically: Brotli for browsers that support it, gzip for the others. See which method each domain uses on the Compression card and confirm it with curl.

HTTP/3 (QUIC): turn it off for a hostname

HTTP/3 is on for every HTTPS hostname by default. Turn it off for one hostname in its details on the Domains tab of Domains & Rules when its visitors, or a network they use, have trouble with QUIC; those visitors then use HTTP/2.

CORS headers at the edge

Add Access-Control-Allow-Origin and the other CORS headers to a delivery rule's responses, let your origin answer preflight OPTIONS requests, and allow the methods your API uses in the WAF.