Access URL Rewrite
You can set access URL rewrite rules to redirect user requests to the URLs of cached content.
Scenarios
If the path for storing server resources changes, the path for storing resources on CDN PoPs changes accordingly. For example, the path of an image has changed from /test to /testnew. If a user sends a request to the original URL, CDN PoPs need to rewrite the requested URL.
If a URL rewrite rule has been configured, CDN matches URLs in redirection mode and uses the HTTP 302 status code (302 Found) to indicate that the requested resource has been temporarily moved to another location. Specifically, CDN PoPs add the new URL to the HTTP Location header in the 302 response to the client. After receiving the response, the client sends a request to the new URL. Table 1 lists the redirection status codes and their meanings.
Code |
Meaning |
Processing Method |
Description |
---|---|---|---|
301 |
Moved Permanently |
The GET method does not change. Other methods may change to the GET method. |
The resource is moved permanently. |
302 |
Found |
The GET method does not change. Other methods may change to the GET method. |
This page is temporarily unavailable for unforeseen reasons. |
303 |
See Other |
The GET method does not change. Other methods are changed to the GET method (the message body is lost). |
Used to redirect after a PUT or a POST, so that refreshing the result page does not re-trigger the operation. |
307 |
Temporary Redirect |
Neither the method nor the message body changes. |
This page is temporarily unavailable for unforeseen reasons. Better than 302 when non-GET operations are available on the site. |
Procedure
-
Log in to Huawei Cloud console. Choose .
The CDN console is displayed.
- In the navigation pane, choose .
- In the domain list, click the target domain name or click Configure in the Operation column.
- Click the Cache Settings tab.
- In the Access URL Rewrite area, click Add.
Figure 1 Adding an access URL rewrite rule
Table 2 Parameters Parameter
Description
Content Type
- Directory: Execute the rule for files in the specified directory.
- Full path: Execute the rule for the file under the specified path.
- Home page: Execute the rule when the homepage of the domain name is visited.
Content
- When Content Type is set to Directory, enter up to 20 directories and separate them by commas (,). A directory starts with a slash (/). Wildcards (*) are not supported. Example: /test/folder01,/test/folder02
- When Content Type is set to Full path, enter the path of a file or a path with wildcards (*). A path must start with a slash (/) and cannot end with a wildcard (*). Only one wildcard (*) can be entered. Examples: /test/index.html or /test/*.jpg
- When Content Type is set to Home page, this parameter is left blank. You can configure only one rule for the homepage.
- Regular expression match is not supported.
Redirection URL
Target URL. Start with a slash (/) and do not contain http://, https://, or the domain name. Example: /newtest/index.html
- When Content Type is set to Full path, the wildcard (*) can be captured by $1. For example, if Content is set to /test/*.jpg and Redirection URL is set to /newtest/$1.jpg, when a user requests /test/11.jpg, $1 is replaced by 11, so the requested URL after redirection is /newtest/11.jpg.
Action
Select Redirect or Break.
- Redirect: If the requested URL matches this rule, the request is redirected to the target URL. After this rule is executed, if other rules exist, CDN continues to execute these rules.
- Break: If the requested URL matches this rule, the request is rewritten as the target URL. After this rule is executed, CDN does not execute any other rules and returns status code 200. You cannot set the redirection host or status code.
Redirection Host
Domain name to which client requests are redirected. Specify the value when Action is set to Redirect.
- By default, the acceleration domain name is used.
- The value contains 1 to 255 characters and starts with http:// or https://, for example, http://www.example.com.
Redirection Status Code
Specify the value when Action is set to Redirect. The status code can be 301, 302, 303, or 307. For details about their differences, see Table 1.
Priority
Priority of the rule. Enter an integer ranging from 1 to 100. A greater number indicates a higher priority.
Each rule must have a unique priority.
- Click OK.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot