Origin Path Rewrite

CDN modifies the path of the request URL when fetching from the origin.

After configuring origin path rewriting, when a user requests a file that is not cached, the CDN will rewrite the path in the URL to the new path in the origin request.

Configuration
Description

Priority

Represents the priority of the rule. A rule with a number 1 has the highest priority.

When receiving a request, CDN tries to match the request with the rules from highest to lowest priority. If a request matches a rule, the CDN stops matching the remaining rules.

You can adjust the priority of rules by dragging and dropping.

Path Pattern

Specifies the path in the user request URL, with a maximum length of 1,024 characters. The path does not include the protocol, domain name, or query parameters.

You can use regular expressions in this setting, in which case it defines a matching rule. Groups can also be specified in the regular expression by enclosing them in parentheses (). These groups can then be referenced in the CDN origin path configuration.

For example, ^/a/b/(.*)$ matches all directories and files under the /a/b/ path.

Target Path

Specifies the path that replaces the user request path in the origin request URL. This configuration must meet the following requirements:

  • The length must not exceed 1,024 characters;

  • It cannot contain consecutive slashes (//), percent signs (%), spaces, or question marks (?).

  • It must not include the protocol, domain name, or query string.

The CDN retains the query string from the request URL and appends it to the actual origin URL. If the User Request Path configuration contains a regular expression with one or more capture groups, you can use in the CDN origin path configuration to reference the captured group. 1 represents the first group, 2 the second, and so on. In this case, the configuration defines a matching rule. Based on the example in the User Request Path configuration, suppose you specify the origin path as /c/1. Here, /c/$1 indicates that the path starts with /c/, and the remainder of the path corresponds to the portion matched by .* in the user request path. If the user request URL is https://www.example.com/a/b/test/1.png, the origin request URL will be rewritten as https://www.example.com/c/test/1.png.

Last updated