The rewrite feature allows you to modify the Uniform Resource Identifiers (URIs) of requests by creating rewrite rules. After Dynamic Route for CDN (DCDN) receives a request, it matches the request against the rewrite rules. If a match is found, DCDN performs a 302 redirect to redirect the request to the specified target URI. You can create multiple rewrite rules as needed. This topic describes how to configure rewrite rules in the DCDN console.

Background information

If you need to modify the requested URI, create a rewrite rule. For example, if a client requests to access http://example.com over HTTP, you can create a rewrite rule to redirect all requests for http://example.com to https://example.com.

Procedure

  1. Log on to the Dynamic Route for CDN 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. On the Rewrite tab, click Create.
  5. In the dialog box that appears, specify the original URI to be rewritten, the target URI, and the rewrite flag.
    The following redirect flags are available:
    • Redirect: When the requested URI matches the current rule, DCDN returns a 302 status code and redirects the request to the target URI.
    • Break: When the requested URI matches the current rule, DCDN returns the content of the target URI, and stops matching the requested URI against the remaining rules.
    Rewrite
  6. Click OK.

    After the rewrite rule is created, you can click Modify or Delete in the Actions column to modify or delete the rule.

    Note A domain supports up to 50 rewrite rules.

Example

Example Requested URI Target URI Redirect flag Description
Example 1 /hello /index.html Redirect When a client requests the content of http://domain.com/hello, DCDN returns a 302 status code and redirects the client to http://domain.com/index.html.
Example 2 ^/hello$ /index.html Break When a client requests the content of http://domain.com/hello, DCDN returns the content of http://domain.com/index.html, and stops matching the requested URI against the remaining rewrite rules.
Example 3 ^/$ /index.html Redirect When a client requests the content of http://domain.com, DCDN returns a 302 status code and redirects the client to http://domain.com/index.html.