All Products
Search
Document Center

ApsaraVideo VOD:Rewrite URLs in origin requests

Last Updated:Feb 09, 2026

ApsaraVideo VOD lets you rewrite URLs in back-to-origin requests. This rewrite does not affect the internal routing or cache keys of Alibaba Cloud CDN. It applies only when CDN nodes send back-to-origin requests to your origin server. This topic describes how to configure origin URL rewrite.

How it works

POPs match origin paths against the URLs of the requested resources on the origin server based on URL rewrite rules. Then, the requests with specific parameters are redirected to the origin server.

  • In a rewrite rule, if you set the Flag parameter to None or Break, only the resource path in the URL is rewritten.1

  • If you set the Flag parameter to enhance break, the resource path and query string are rewritten.2

Usage notes

  • You can configure up to 50 Origin Path Rewrite rules for each domain name.

  • The system runs the rewrite rules that are listed on the Origin Path Rewrite tab in order from top to bottom. A change to this order may lead to a different rewrite result.

  • The Origin URL Rewrite feature may conflict with the Ignore Parameters feature on the Domain Names > Performance Optimization tab if you configure rules to rewrite URL parameters. When you configure these features, ensure that you avoid conflicts.

Procedure

  1. Log on to the ApsaraVideo VOD console.

  2. In the left-side navigation pane, choose Configuration Management > CDN Configuration > Domain Names.

  3. Click Configure for the target domain name.

  4. In the navigation pane on the left, click Back-to-Origin.

  5. Click the Origin URL Rewrite tab.

  6. Click Add. Then configure the Source Path, Destination Path, and Flag according to your requirements.

    Important

    The system runs rewrite rules sequentially from top to bottom on the Origin URL Rewrite tab. Changing the order of the rules may affect the rewrite results.

    Parameter

    Example

    Description

    Path to be rewritten

    ^/hello$

    Enter a URL that starts with a forward slash (/). Do not include http:// or domain names. Perl Compatible Regular Expressions (PCRE) are supported.

    Destination Path

    /hello/test

    Enter a URL that starts with a forward slash (/). The URL cannot contain http:// or a domain name.

    Execution rule

    Empty

    If multiple rules are configured, the system processes them from top to bottom. All matching rules are executed in this order.

    break

    • If multiple URL rewrite rules are set, and a rule is matched, the remaining rules are skipped.

    • This feature rewrites only the resource path in the URL. The URL parameters remain unchanged. Use the back-to-origin parameter rewrite feature to rewrite URL parameters.

    enhance break

    • If multiple URL rewrite rules are configured, and the request URL matches the current rule, other rules are skipped after the current rule is executed.

    • Similar to `break`, but adds the ability to rewrite URL parameters, .

  7. Click OK to enable the rewrite rule.

    You can click Modify or Delete in the rule list on the Origin URL Rewrite page to modify or delete the currently configured rules.

Configuration examples

Example 1: Apply a rule with the Empty flag

Path to Be Rewritten

^/hello$

Target Path

/index.html

Flag

None

Expected result

Original request: http://example.com/hello

Final request: http://example.com/index.html

The system continues to match the request against other URL rewrite rules that are listed on the Origin Path Rewrite tab.

Example 2: Apply a rule with the break flag

Path to Be Rewritten

^/hello.jpg$

Target Path

/image/hello.jpg

Flag

break

Expected result

Original request: http://example.com/hello.jpg

Final request: http://example.com/image/hello.jpg

The system stops matching the request against other URL rewrite rules that are listed on the Origin Path Rewrite tab.

Example 3: Apply a rule with the enhance break flag

Path to Be Rewritten

^/hello.jpg?code=123$

Target Path

/image/hello.jpg?code=321

Flag

enhance break

Expected result

Original request: http://example.com/hello.jpg?code=123

Final request: http://example.com/image/hello.jpg?code=321

The system stops matching the request against other URL rewrite rules that are listed on the Origin Path Rewrite tab.

Example 4: Add a URL prefix to the root directory when the file name is variable

Add the /image path to the URLs of all files in the root directory. For example, rewrite /xxx in URLs to /image/xxx. In this example, xxx is a file name, such as hello.jpg or hello.html.

Path to Be Rewritten

^(.*)$

Note

^ matches a string from the beginning of the string. (.*) is a group, in which . matches any character except a line feed. * matches the preceding character or group zero or more times. You can use $1 in the target path to reference the variable content of the group. $ matches a string to the end of the string. ^(.*)$ matches a string from the beginning to the end of the string, which can contain any character except a line break, and then captures the matched content into a group. For example, for a string "hello world", ^(.*)$ matches the entire string and captures "hello world" into the first group.

Target Path

/image$1

Note

/image matches the string "/image". $1 references the content of the first group, $2 references the content of the second group, and so forth. /image$1 matches the string "/image" followed by the content of the first group. For example, if the content of the first group is "abc", /image$1 matches the string "/imageabc". Note that the $1 references the content of the group instead of the literal "$1". If you want to match the literal "$1", use the escaped string "\$1".

Flag

break

Expected result

  • Original request: http://example.com/hello.jpg

    Final request: http://example.com/image/hello.jpg

  • Original request: http://example.com/hello.html

    Final request: http://example.com/image/hello.html

The system stops matching the request against other URL rewrite rules that are listed on the origin path Rewrite tab.

Example 5: Add a URL prefix to a specified directory when the file name is variable

Add the /image path to the URLs of all files in the /live directory. For example, rewrite /live/xxx in URLs to /image/live/xxx. In this example, xxx is a file name, such as hello.jpg or hello.html.

Path to Be Rewritten

^/live/(.*)$

Target Path

/image/live/$1

Flag

break

Expected result

  • Original request: http://example.com/live/hello.jpg

    Final request: http://example.com/image/live/hello.jpg

  • Original request: http://example.com/live/hello.html

    Final request: http://example.com/image/live/hello.html

The system stops matching the request against other URL rewrite rules that are listed on the origin path Rewrite tab.

Example 6: Apply the Empty flag when multiple rules match

Configure two rules, as shown in the following figure:

域名管理-改写回源URL1.png

Expected result:

  • Original request: http://example.com/image_01.png

  • Final request: http://example.com/image/image_02.png

    Note

    The request matches the first rule and the origin path is rewritten to http://example.com/image_02.png. Then, the request matches the second rule and the origin path is rewritten to http://example.com/image/image_02.png.

Example 7: Apply the break flag when multiple rules match

Configure two rules, as shown in the following figure:

域名管理-改写回源URL2.png

Expected result:

  • Original request: http://example.com/image_01.png

  • Final request: http://example.com/image_02.png

    Note

    The request matches the first rule and the request URL is rewritten to http://example.com/image_02.png. Other rules are skipped.

References

Batch Domain Name Configuration