The rewrite feature allows you to modify the Uniform Resource Identifiers (URIs) of requests by creating rewrite rules. Based on rewrite rules, you can redirect HTTP requests to the HTTPS versions of web pages. You can also change your accessed URI to the URI of the origin if the two URIs are different. After Dynamic Route for CDN (DCDN) receives a request, DCDN matches the request against the rewrite rules. If a match occurs, DCDN performs a 302 redirect to redirect the request to the specified destination URI. You can create multiple rewrite rules based on your business needs. 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 the requests for http://example.com to https://example.com.

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 domain name that you want to manage, and click Configure in the Actions column.
  4. In the left-side navigation pane on the details page of the specified domain, click Caching.
  5. On the Rewrite tab, click Add.
  6. In the Rewrite dialog box, specify the URI to Be Rewritten, Target URI, and Executing Rules parameters based on your business needs.
    Rewrite
    Parameter Example Description
    URI to Be Rewritten /domain/image/123.png The specified URI can include neither the protocol information nor the domain name. The specified URI must start with a forward slash (/). Perl-compatible regular expressions (PCREs) are supported.
    Target URI /domain/image/123.gif The specified URI can include neither the protocol information nor the domain name. The specified URI must start with a forward slash (/).
    Executing Rules Redirect Redirect: When the requested URI matches the current rule, DCDN returns a 302 status code and redirects the request to the destination URI.
    Break Break: When the requested URI matches the current rule, DCDN returns the content of the destination URI, and stops matching the requested URI against the remaining rules.
  7. Click OK.

    On the Rewrite page, you can click Modify or Delete to manage the rewrite rule.

    Note You can configure a maximum of 50 rewrite rules for each domain name.

Example

Example URI to Be Rewritten Target URI Executing Rules 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. DCDN 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.