Origin URL Rewriting
If the URLs of origin pull requests do not match the origin server URLs, origin pull fails. You can rewrite origin URLs to origin server URLs, improving the origin pull hit ratio.
Scenarios
Assume that you have changed the storage path of a video file on the origin server from /test/ to /video/. Users may fail to obtain the correct file if they use the original access URL. In this case, you can use this function to rewrite URLs for CDN to pull the file, so users can obtain the correct file without changing the access URL.
Constraints
- You can add up to 20 URL rewrite rules.
- This function is not available if you have signed URLs using method B or C1.
- If the service type of your domain name is whole site acceleration, this function takes effect only for static resources.
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 Origin Settings tab.
- In the Origin URL Rewrite area, click Edit.
Figure 1 Rewriting origin URLs
Table 1 Parameter description Parameter
Description
Match Mode
All files: Rewrites URLs of pulling all files under this domain name from the origin server.
Path: Rewrites URLs of pulling files under a specific path from the origin server. Prefix match is used. For example, if the original URI is /test, all files whose prefix is /test (such as /test, /test01, and /test**) will be matched.
Wildcard: Wildcard characters (*) are supported. Files are matched by full path. The original URI must be a specific path, for example, /test/*/*.mp4.
Full path: Rewrites the entire URL. The original URI must be a specific path, for example, /test/01/abc.mp4.
Original URI
URI to be rewritten.
- A URI starts with a slash (/) and does not contain http://, https://, or the domain name.
- A URI contains up to 512 characters.
- Wildcards (*) are supported, for example, /test/*/*.mp4.
- When Match Mode is Path or Full path, no parameters can be specified.
- When Match Mode is Wildcard and a slash (/) is entered, the root directory is matched.
Target URI
URI after rewrite.
- A URI starts with a slash (/) and does not contain http://, https://, or the domain name.
- A URI contains up to 256 characters.
- When Match Mode is set to Wildcard, the nth wildcard (*) field can be substituted by $n, where n = 1, 2, 3.... Assume that the source URI is /test/*/*.mp4 and the target URI is /newtest/$1/$2.mp4. When a user requests /test/11/22.mp4, $1 captures 11 and $2 captures 22, and the actual URI for origin pull is /newtest/11/22.mp4. Other match modes do not support $n.
Priority
Priority of a URL rewrite rule.
- The priority of a rule is mandatory and must be unique.
- The rule with the highest priority will be used for matching first.
- The priority is an integer ranging from 1 to 100. A greater number indicates a higher priority.
Examples
Example 1: Assume that you have configured the following rewrite rule for domain name www.example.com.
Original origin pull request: https://www.example.com/test/a.txt
Rewritten origin pull request: https://www.example.com/test/b.txt
Example 2: Assume that you have configured the following rewrite rule for domain name www.example.com.
Original origin pull request: https://www.example.com/test/aaa/bbb.mp4
Rewritten origin pull request: https://www.example.com/newtest/aaa/bbb.mp4
Example 3: Assume that you have configured the following rewrite rule for domain name www.example.com.
Original origin pull request: https://www.example.com/test/aaa/bbb.txt
Rewritten origin pull request: https://www.example.com/new.jpg
Example 4: Assume that you have configured the following rewrite rule for domain name www.example.com.
Original origin pull request: https://www.example.com/123.html?id=3
Rewritten origin pull request: https://www.example.com/thread0/123.html?id=3
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.