# 回源路径改写

配置回源路径改写，该配置允许对 CDN 的回源路径进行改写。

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

在您对某个文件配置了回源路径改写后，用户请求文件，如果该文件未被缓存，CDN 根据配置，在回源请求中将来自用户请求 URL 中的路径改写成新的路径。

<table><thead><tr><th width="128.16259765625">配置</th><th>说明</th></tr></thead><tbody><tr><td>优先级</td><td><p>表示规则的优先级。数字 1 的规则优先级最高。</p><p>在收到请求时，CDN 按规则的优先级，从高到低尝试将请求与规则匹配。如果请求匹配了某一条规则，CDN 就停止匹配其余规则。</p><p>您可以通过拖拽调整规则的优先级。</p></td></tr><tr><td>用户请求路径正则匹配</td><td><p>表示用户请求 URL 中的路径，长度不超过 1,024 个字符。路径不包含协议、域名和参数。</p><p>您可以在该配置中使用正则表达式。此时，该配置表示一个匹配规则。同时，您可以在正则表达式中指定组，组是由 () 包裹的。这些组可以在 CDN 回源路径 配置中被引用。</p><p>例如，^/a/b/(.*)$ 表示路径 /a/b/ 下的所有目录和文件。</p></td></tr><tr><td>回源路径</td><td><p>表示在回源请求 URL 中替换 用户请求路径 的路径。该配置的要求：</p><ul><li>长度不超过 1,024 个字符；</li><li>不能包含连续斜杠（//）、百分号（%）、空格、问号（?）。</li><li>不包含协议、域名和查询字符串。</li></ul><p>CDN 会将请求 URL 中的查询字符串保留，添加到实际的回源 URL 中。<br>如果用户请求路径配置中包含了正则表达式并且正则表达式包含了一个或者多个捕获，您可以在 CDN 回源路径配置中使用 指定需要使用的捕获。</p><p>1 表示第一个，2 表示第二个，以此类推。此时，该配置表示一个匹配规则。<br>就基于 用户请求路径 配置中的例子，假设您指定的回源路径是 /c/1。/c/$1 表示的路径是以 /c/ 开头。路径的其余部分就是用户请求路径中由 .* 所表示的部分。如果用户请求 URL 是<code>https://www.example.com/a/b/test/1.png</code>，回源请求 URL 会被改写为<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/cn/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.
