Skip to main content
The Rewrite option changes or redirects request paths before the CDN fetches content from the origin. It operates according to nginx rewrite rules. To enable the option, open a CDN resource, navigate to the Options tab, then to the Content section. Toggle Enable rewrite. The same setting is available in the Rules section.
CDN resource Options tab with Rewrite enabled, showing the Rewrite body field and Rewrite flag dropdown
The Rewrite body field pre-fills with /(.*) /$1 as an example. Replace it with two space-separated directives using regular expressions:
  1. The path the Rewrite applies to.
  2. The replacement path.
To rewrite all request paths to the /media/ directory, use:
where:
  • /(.*) — matches all paths after /. The (.*) group captures everything that follows the slash.
  • /media/ — the directory on the origin where CDN servers look for content.
  • $1 — references the first capture group. Use $2 and $3 for the second and third groups.
In the Rewrite flag dropdown, select the nginx flag that controls how the rewrite is applied:
  • break (default) — stops processing further rewrite rules after this one.
  • last — stops processing rewrite rules and starts a new location search.
  • redirect — returns a 302 temporary redirect to the client.
  • permanent — returns a 301 permanent redirect to the client.