API
The Gcore Customer Portal is being updated. Screenshots may not show the current version.
CDN
CDN
BillingCDN resources overviewOrigin groupPurgePrefetchReports
API
Chosen image
Home/CDN/CDN resource options/Rewrite

Rewrite: redirect requests from the CDN to the origin

Rewrite option is useful for changing or redirecting query paths. The option works accordingly to nginx configuration.

To enable Rewrite click Add Option in "Content" section and choose Enable Rewrite. You also can set up Rewrite in the Rules section.

After the option activation, some default values are shown in Rewrite body field. Clear the field and enter two space-separated directives: a path the Rewrite option is applied to and a path to be used instead. Use regular expressions. 

Rewrite body field

For example, you need to apply Rewrite to all the resource and make CDN-servers get the content from the certain directory on your origin. Let's say that origin is example.com and directory is /media/, to set up Rewrite fill the "Rewrite" field with the following:

/(.*) /media/$1

where:

  • /(.) is the group of variables for which one Rewrite is applied. With this (.) group Rewrite; will be applied for all of the possible variants which can appear after / in example.com/;
  • /media/ is the directory, where CDN servers will go for the content;
  • $1 is the number of the group of variables. If you have more than one group, the next numbers will be $2, $3 and so on.

Break flag is applied to the option by default. It is not shown in the field. You may apply to the option any other ngnix flags via API documentation.

Was this article helpful?

Not a Gcore user yet?

Learn more about our next-gen CDN

Go to the product page