You can create a URI rewrite rule to redirect requests from HTTP URIs to HTTPS URIs, or rewrite URIs in requests to the URIs of the requested resources.

Scenarios

If you want to rewrite URIs in requests to the URIs of the requested resources, you can create a URI rewrite rule. If a request matches the rewrite rule, Alibaba Cloud Dynamic Route for CDN (DCDN) performs a 302 redirect to redirect the request to the final URI. For example, users visit www.example.com/hello over HTTP. After you create a rewrite rule, requests that are sent to www.example.com/hello are redirected to www.example.com/index.html.

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 name, click Caching.
  5. Click the URI Rewrite tab.
  6. Click Add and configure URI to Be Rewritten, Target URI, and Executing Rules based on your business requirements.
    Note You can create up to 50 rewrite rules for each domain name.
    Create a rewrite rule
    Parameter Description
    URI to Be Rewritten Enter a URI that starts with a forward slash (/). The URI cannot contain http:// or domain names. You can use Perl Compatible Regular Expressions (PCRE) to specify the URI, for example, ^/hello$.
    Target URI Enter a URI that starts with a forward slash (/). The URI cannot contain http:// or domain names. Example: /index.html.
    Executing Rules Redirect and Break are supported.
    • Redirect: If the URI in a request matches the current rule, Alibaba Cloud DCDN performs a 302 redirect to redirect the request to the final URI.
    • Break: If the URI in a request matches the current rule, Alibaba Cloud DCDN returns the content of the final URI and skips other rewrite rules.
  7. Click OK.

    After a rewrite rule is created, it is displayed on the URI Rewrite tab. You can Modify or Delete the rule.

Configuration examples

Example URI to Be Rewritten Target URI Executing Rules Description
Example 1 /hello /index.html Redirect A client requests example.aliyundoc.com/hello. DCDN nodes perform a 302 redirect to redirect the request to example.aliyundoc.com/index.html.
Example 2 ^/$ /index.html Redirect A client requests example.aliyundoc.com. DCDN nodes perform a 302 redirect to redirect the request to example.aliyundoc.com/index.html.
Example 3 /hello /hello/index.html Redirect A client requests example.aliyundoc.com/hello. DCDN nodes perform a 302 redirect to redirect the request to example.aliyundoc.com/hello/index.html.
Example 4 ^/hello$ /index.html Break A client requests example.aliyundoc.com/hello. DCDN nodes return the content of example.aliyundoc.com/index.html and skip the subsequent rules.

API operations

BatchSetDcdnDomainConfigs