If the path of a resource on the origin server changes, the resource is no longer accessible at its original path on CDN points of presence (POPs). If a client requests the resource using the original URL, CDN can rewrite the request URL and redirect the request to the destination path. This reduces origin fetch requests and improves client access performance.
Background
The HTTP 302 status code (302 Found) indicates that a resource has been temporarily moved. After you configure the access URL rewrite feature, CDN POPs return a 302 response that includes the new URL in the HTTP Location header. After the client receives the 302 response, it sends a new request to the specified URL.
By default, after you configure an access URL rewrite rule, an Alibaba Cloud CDN POP sends a 302 redirection status code to the client. The 303 and 307 redirection status codes are also supported.
Status code | Meaning | Processing method | Use case |
302 | Found | The GET method does not change. Other methods may change to the GET method. | A webpage is temporarily unavailable for unforeseeable reasons. In this case, search engines do not update their links. |
303 | See Other | The GET method does not change. Other methods change to the GET method. The message body is lost. | Used for page redirection after a PUT or POST request is complete. This prevents the same operation from being triggered again if the page is refreshed. |
307 | Temporary Redirect | The method and message body do not change. | A webpage is temporarily unavailable for unforeseeable reasons. In this case, search engines do not update their links. This status code is preferred over the 302 status code when the site supports links or operations that use methods other than GET. |
You can configure up to 50 rewrite rules for a single domain name. If multiple rules exist, they are processed from top to bottom in the order that they are listed on the Access URL Rewrite page in the ApsaraVideo VOD console.
Procedure
Log on to the ApsaraVideo VOD console.
In the left-side navigation pane, choose Configuration Management > CDN Configuration > Domain Names.
In the row for the target domain name, click Configure.
In the left navigation tree, click Cache.
Click the Access URL Rewrite tab.
Click Add and configure the parameters as required.
Parameter
Description
Source Path
The path must start with a forward slash (
/) and exclude the protocol and domain. PCRE is supported. Example:^/hello$.Destination Path
If you set Flag to Break, the path must start with a forward slash (
/) and exclude the protocol and domain name.If you set Flag to Redirect, the path can include the protocol and domain name. PCREs are supported. For example,
$1and$2are used to reference captured strings in parentheses in the path that you want to rewrite.
Flag
By default, Redirect and Break are supported.
Redirect: If a request URL matches a rule, the request is redirected to the destination URL with a 302 status code. The Location header in the response that the POP returns to the client is the destination URL. The parameters in the original URL are not modified. After the current rule is executed, the request continues to be matched against the remaining rules.
Break: If a request URL matches a rule, the request is rewritten to the destination URL. The parameters in the original URL are not modified. After the current rule is executed, the remaining rules are skipped.
The Empty, enhance-break, and enhance_redirect flags are also supported. To use these flags, submit a ticket to have them configured in the backend.
Empty: If you configure multiple rules and a request URL matches a rule, the request continues to be matched against the subsequent rules after the current rule is executed.
enhance_break: Similar to Break, but modifies the entire URL, including parameters.
enhance_redirect: Similar to Redirect, but modifies the entire URL, including parameters.
NoteDifferent flags use different rewrite methods. Whether the rewritten URL supports other domain names and protocols also varies:
Empty, Break, and enhance_break directly rewrite the user request URL. They do not support rewriting to other domain names or protocols. For example, you cannot use these flags to change the protocol from HTTP to HTTPS.
Redirect and enhance_redirect use 302 redirection to rewrite a URL. They support rewriting to other domain names and protocols:
You can set the 302 Location address to the current accelerated domain name or another domain name. This lets you rewrite a URL that uses the
example.comdomain name to a new URL that uses thealiyundoc.comdomain name.The 302 Location address supports other protocols. This lets you rewrite a URL that uses the HTTP protocol to a new URL that uses the HTTPS protocol.
Click OK.
After the rewrite rule is configured, it appears in a list where you can Modify or Delete it.
Configuration example
A rewrite rule is configured with a regular expression as follows:
Source path: ^/hello$
Destination path: /index.html
Flag: Redirect
A client requests http://example.aliyundoc.com/hello. Because the path /hello matches the regular expression, the Alibaba Cloud CDN POP returns a 302 response. The Location header of the response contains the new URL http://example.aliyundoc.com/index.html. The client then sends a request to http://example.aliyundoc.com/index.html.