# Origin Path Rewrite

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

<figure><img src="/files/BgGPWYkQN1cq68WMkxYz" alt=""><figcaption></figcaption></figure>

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.

<table><thead><tr><th width="149.75311279296875">Configuration</th><th>Description</th></tr></thead><tbody><tr><td>Priority</td><td><p>Represents the priority of the rule. A rule with a number 1 has the highest priority.</p><p>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.</p><p>You can adjust the priority of rules by dragging and dropping.</p></td></tr><tr><td>Path Pattern</td><td><p>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.</p><p>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.</p><p>For example, ^/a/b/(.*)$ matches all directories and files under the /a/b/ path.</p></td></tr><tr><td>Target Path</td><td><p>Specifies the path that replaces the user request path in the origin request URL. This configuration must meet the following requirements:</p><ul><li>The length must not exceed 1,024 characters;</li><li>It cannot contain consecutive slashes (//), percent signs (%), spaces, or question marks (?).</li><li>It must not include the protocol, domain name, or query string.</li></ul><p>The CDN retains the query string from the request URL and appends it to the actual origin URL.<br>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.<br>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 <code>https://www.example.com/a/b/test/1.png</code>, the origin request URL will be rewritten as <code>https://www.example.com/c/test/1.png</code>.</p></td></tr></tbody></table>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.console.zenlayer.com/welcome/content-delivery-network/domain-management/cdn-settings/origin-path-rewrite.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
