ApsaraVideo VOD allows you to rewrite the URL of a back-to-origin request without affecting internal CDN pathways or the cache key. A point of presence (POP) uses the rewritten URL only when it sends a back-to-origin request to the origin.
How it works
Origin Path Rewrite rules let you modify the request path to match the actual resource location on your origin server. This ensures that POPs can accurately retrieve resources or pass specific query strings to the origin.
-
If the Flag is set to None or break, only the resource path in the URL is rewritten.

-
If the Flag is set to enhance break, both the resource path and the query string can be rewritten.

Usage notes
-
You can configure up to 50 Origin Path Rewrite rules for a single domain name.
-
Rules are applied from top to bottom. Their order affects the final rewrite result.
-
When you configure an execution rule for origin URL rewrite, rewriting URL parameters may conflict with the Ignore Parameters feature on the Domain Names > Performance Optimization tab. If you configure both features, make sure their settings do not conflict.
Procedure
-
Log on to the ApsaraVideo VOD console.
In the left-side navigation pane, choose Configuration Management > CDN Configuration > Domain Names.
-
Find the domain name that you want to manage and click Configure in the Actions column.
-
In the left-side navigation pane for the domain name, click Back-to-Origin.
-
Click the Origin URL Rewrite tab.
-
Click Add and configure the source path, destination path, and execution rule based on your requirements.
ImportantRewrite rules on the Origin URL Rewrite page are executed sequentially from top to bottom, which can affect your rewrite results.
Parameter
Example
Description
Source Path
^/hello$
The URL path to match. It must start with a forward slash (/) and must not include the
http://prefix or a domain name. Perl Compatible Regular Expressions (PCRE) are supported.Destination Path
/hello/test
The URL path to use for the rewrite. It must start with a forward slash (/) and must not include the
http://prefix or a domain name.execution rule
Empty
If a request URL matches the rule, the system applies the rewrite and continues processing. The rewritten URL is then evaluated against subsequent rules.
break
-
If a request URL matches this rule, the system executes the rule and stops processing subsequent rules.
-
This option rewrites only the resource path in the URL, not URL parameters. It does not conflict with the parameter rewrite feature.
enhance break
-
If a request URL matches this rule, the rule is executed and no subsequent rules are processed.
-
Similar to
break, but this option can also rewrite URL parameters. .
-
-
Click OK to apply the rewrite rule.
On the Origin URL Rewrite tab, you can also click Modify or Delete in the rule list to manage existing rewrite rules.
Configuration examples
Example 1: Empty execution rule
|
Path to Be Rewritten |
^/hello$ |
|
Target Path |
/index.html |
|
Flag |
None |
|
Result |
Original request: Origin fetch request after rewrite: The request is then matched against subsequent rules in the Origin Path Rewrite list. |
Example 2: Break execution rule
|
Path to Be Rewritten |
^/hello.jpg$ |
|
Target Path |
/image/hello.jpg |
|
Flag |
break |
|
Result |
Original request: Origin fetch request after rewrite: No subsequent rules in the Origin Path Rewrite list are evaluated. |
Example 3: Enhance break execution rule
|
Path to Be Rewritten |
^/hello.jpg?code=123$ |
|
Target Path |
/image/hello.jpg?code=321 |
|
Flag |
enhance break |
|
Result |
Original request: Origin fetch request after rewrite: No subsequent rules in the Origin Path Rewrite list are evaluated. |
Example 4: Add a prefix to root paths
For example, you can rewrite a URL path like /xxx, where xxx is a variable filename (e.g., /hello.jpg or /hello.html), to /image/xxx. This inserts the /image prefix into the path for any file in the root directory.
|
Path to Be Rewritten |
^(.*)$ Note
|
|
Target Path |
/image$1 Note
|
|
Flag |
break |
|
Result |
No subsequent rules in the Origin Path Rewrite list are evaluated. |
Example 5: Add a prefix to specified paths
For example, you can rewrite a URL that contains /live/xxx, where xxx represents any filename (e.g., hello.jpg or hello.html), to /image/live/xxx. This inserts the /image prefix into the path for any file under the /live directory.
|
Path to Be Rewritten |
^/live/(.*)$ |
|
Target Path |
/image/live/$1 |
|
Flag |
break |
|
Result |
No subsequent rules in the Origin Path Rewrite list are evaluated. |
Example 6: Matching multiple rules with the empty rule
Consider two enabled rules. Rule 1: Source Path is ^/image_01.png$, Destination Path is /image_02.png, and execution rule is Empty. Rule 2: Source Path is ^(.*)$, Destination Path is /image$1, and execution rule is Empty.
Result:
-
Original request:
http://example.com/image_01.png -
Origin fetch request after rewrite:
http://example.com/image/image_02.pngNoteThe request first matches Rule 1 and is rewritten to
http://example.com/image_02.png. Because the Flag is set to None, the rewritten path is then evaluated against Rule 2, which also matches. The path is rewritten a second time, resulting in the final path:http://example.com/image/image_02.png.
Example 7: Matching multiple rules with the break rule
Consider two enabled rules. Rule 1: Source Path is ^/image_01.png$, Destination Path is /image_02.png, and execution rule is break. Rule 2: Source Path is ^(.*)$, Destination Path is /image$1, and execution rule is Empty.
Result:
-
Original request:
http://example.com/image_01.png -
Origin fetch request after rewrite:
http://example.com/image_02.pngNoteThe request first matches Rule 1 and is rewritten to
http://example.com/image_02.png. Because the Flag for Rule 1 is set to break, processing stops and no subsequent rules are evaluated.