All Products
Search
Document Center

Edge Security Acceleration:Create a URI rewrite rule

Last Updated:Sep 21, 2026

When a resource on the origin server is relocated, Dynamic Content Delivery Network (DCDN) points of presence (POPs) rewrite outdated request URLs and redirect them to the new path. This reduces back-to-origin requests and improves access performance.

Note

Note: When this feature references rule conditions from the Rules Engine, the execution order follows the priority order of the rule conditions configured in the Rules Engine, NOT the priority order of this feature's own configuration.

Background information

HTTP status code 302 (Found) indicates that the requested resource has been temporarily relocated. When a URI rewrite rule is configured, DCDN POPs add the new URI to the Location header in the HTTP 302 response. The client then sends a follow-up request to the new URI.

In addition to the default status code 302, POPs also support status codes 303 and 307. If you want to change the redirect status code, submit a ticket.

HTTP status code

Description

Handling method

Scenario

302

Found

GET requests remain unchanged. Requests that use other methods may be changed to GET requests.

A web page is temporarily inaccessible due to unknown reasons. Search engines do not update the URL to the web page.

303

See Other

GET requests remain unchanged. Requests that use other methods are changed to GET requests. The message body is dropped.

This status code is used to redirect PUT and POST requests to prevent repeated redirections caused by page refreshes.

307

Temporary Redirect

Both the request method and message body remain unchanged.

A web page is temporarily inaccessible due to unknown reasons. Search engines do not update the URL to the web page. If the website supports request methods other than GET, status code 307 is returned instead of 302.

Important

You can create up to 50 rewrite rules for a domain name. If you configure multiple rewrite rules, the rules are applied in descending order in which they are listed in the DCDN console.

Scenarios

If a resource on the origin server is moved to a different directory, the cached URL on POPs is updated accordingly. When a client sends a request to the original URL, DCDN rewrites and redirects the request to the new URL. For example, an image file is moved from the /download/ directory to the /image/ directory.

image

Procedure

  1. Log on to the DCDN console.

  2. In the left-side navigation pane, click Domain Names.

  3. On the Domain Names page, find the target domain name and click Configure.

  4. In the left-side navigation tree of the domain name, click Caching.

  5. Click the URL Rewrite tab.

  6. Click Add and configure the rewrite rule based on your business requirements.

    Parameter

    Description

    URI to Be Rewritten

    • The path must start with a forward slash (/) and exclude the protocol and domain name.

    • Perl Compatible Regular Expressions (PCRE) are supported. Example: ^/hello$.

    Target URI

    • If you set Flag to Break in a rewrite rule, the path must start with a forward slash (/) and exclude the protocol and domain name.

    • If you set Flag to Redirect in a rewrite rule, the path can contain the protocol and domain name. PCRE is supported. For example, $1 and $2 are used to reference captured strings in parentheses in the path that you want to rewrite.

    Flag

    Valid values: Redirect and Break.

    • Redirect: If the URI in a request matches a rule, the POP returns status code 302 and redirects the request to the URI specified in the Location header. Parameters in the original URI are not modified. After the current rule is executed, the request is matched against other rules.

    • Break: If the URI in a request matches a rule, the POP redirects the request to the target URI. Parameters in the original URI are not modified. After the current rule is executed, remaining rules are skipped.

  7. Click OK.

    After the rewrite feature is created, you can Modify or Delete the rule on the URL Rewrite tab.

Configuration examples

Example 1

When a client requests http://example.aliyundoc.com/hello, the request path is /hello. The POP includes the new URL http://example.aliyundoc.com/index.html in the Location header of the 302 response and returns the response to the client. The client then sends a request to http://example.aliyundoc.com/index.html.

For this rule, Path to Rewrite is set to ^/hello$, Destination Path is set to /index.html, and Execution Rule is set to redirect.

Note

During a 302 redirection, if the Location header does not include a protocol and domain name, the client uses the protocol and domain name from the original request by default.

Example 2

When a client requests http://example.aliyundoc.com/hello, the request path /hello matches the regular expression ^/hello$. The POP returns a 302 response to the client. The response includes the destination URL https://test.aliyundoc.com/index.html in the Location header. After the client receives the response, it sends a request to https://test.aliyundoc.com/index.html.

Configuration rule: Set Path to Rewrite to ^/hello$, set Destination Path to https://test.aliyundoc.com/index.html, and set Execution Rule to redirect.

Example 3

When a client requests http://www.example.com/cdn/url/http://image.example.com/image/cat.jpg, the request path contains /cdn/url/http://, which matches the regular expression ^/cdn/url/http://(.*). The POP returns a 302 response to the client. The response includes the destination URL http://image.example.com/image/cat.jpg in the Location header. After the client receives the response, it sends a request to http://image.example.com/image/cat.jpg.

For the configuration rule, set Destination Path to http://$1 and Execution Rule to redirect.

Example 4

When a client requests http://example.aliyundoc.com/stories/index.html#/voice/318, the #/voice/318 part of the URL is a client-side fragment identifier. The browser does not send this part to the server. The actual request path that the POP receives is /stories/index.html. Therefore, when you configure the rewrite rule, set Path to Rewrite to ^/stories/index\.html$ to match the path before the #. Then, set Destination Path to the target URL and Execution Rule to Redirect.

To redirect multiple source URLs that have different # fragments to different destination URLs, you must configure a separate rewrite rule for each source path. This is because a server cannot distinguish between URLs based on the content that follows the # symbol.

Example 5

Configure a subdirectory homepage: Returning the default homepage file of a subdirectory when a client accesses the subdirectory name is a common requirement for websites. You can use access URL rewriting to implement this capability on the DCDN side without modifying your origin server. For example, if the homepage file is https://www.example.com/cdn/index.html, after the configuration takes effect, a client request to https://www.example.com/cdn or https://www.example.com/cdn/ returns the homepage file.

Before you configure the rules, make sure that the homepage file in the subdirectory on the origin server is accessible. For example, make sure that https://www.example.com/cdn/index.html can be returned as expected.

The request path from a client may or may not end with a forward slash (/). Therefore, you must configure the following two rules to match both cases:

  • Rule 1: Set Path to Rewrite to ^/(.+)/$, set Destination Path to /$1/index.html, and set Execution Rule to Break.

  • Rule 2: Set Path to Rewrite to ^/([^.?#]+)$, set Destination Path to /$1/index.html, and set Execution Rule to Break.

After the configuration takes effect, directly access a subdirectory, such as https://www.example.com/cdn. If the homepage file of the subdirectory is returned as expected, the configuration is successful.

Related API

BatchSetDcdnDomainConfigs