If the requested URI does not match the URI of the requested resource on the origin server, the requested URI must be rewritten to match the destination URI. To rewrite URIs, you must create rewrite rules. After Alibaba Cloud Content Delivery Network (CDN) receives a request, Alibaba Cloud CDN compares the request with the rewrite rules. If the request matches the rules, Alibaba Cloud CDN performs a 302 redirect to redirect the request to the destination URI. You can create one or more rewrite rules based on your business requirements. This topic describes how to create a rewrite rule.
Background information
To enable Alibaba Cloud CDN to rewrite requested URIs, you must create rewrite rules.
For example, if a client requests the content of http://example.com/hello
over HTTP, you can create a rewrite rule to redirect all the requests destined for
http://example.com/hello
to http://example.com/index.html
.
Procedure
Example
{ }
) in the regular expressions. Rewrite rules that contain braces ({ }
) cannot take effect.
Example | Original URI | Destination URI | Rewrite flag | Description |
---|---|---|---|---|
Example 1 | /hello | /index.html | Redirect | When a client requests the content of http://domain.com/hello , the CDN node returns a 302 status code and redirects the request to http://domain.com/index.html .
|
Example 2 | ^/hello$ | /index.html | Break | When a client requests the content of http://domain.com/hello , the CDN node returns the content of http://domain.com/index.html , but stop comparing the requested URI with the remaining rewrite rules.
|
Example 3 | ^/$ | /index.html | Redirect | When a client requests the content of http://domain.com , the CDN node returns a 302 status code and redirects the request to http://domain.com/index.html .
|
Example 4 | /hello | /hello/index.html | Redirect | When a client requests the content of http://domain.com/hello , the CDN node returns a 302 status code and redirects the request to http://domain.com/hello/index.html .
|