After you migrate data to Object Storage Service (OSS), you can configure redirection to ensure that users can access incremental data that is not migrated to OSS. After you configure redirection-based back-to-origin rules for a bucket, when a user accesses a non-existent object in a bucket, OSS redirects the access request to the origin specified by the rules.
Limits
Number of back-to-origin rules
You can configure up to 20 back-to-origin rules for a bucket. OSS matches back-to-origin rules sequentially based on the values of RuleNumber. If a back-to-origin rule is matched, the subsequent rules are ignored. OSS determines whether a request matches a back-to-origin rule based on whether the request meets the conditions specified in the rule. OSS does not check whether the requested object can be obtained from the origin server.
Origin URL
An internal endpoint cannot be used as an origin URL.
Workflow
The redirection-based back-to-origin feature enables OSS to return a redirection response and an HTTP status code 3xx based on the specified back-to-origin conditions and redirection configurations. The following figure shows how redirection-based back-to-origin works.
Scenarios
Seamless data migration from other data sources to OSS
When you use the redirection-based back-to-origin feature to asynchronously migrate data from your client to OSS, OSS returns a 302 redirection request by using URL rewrite for the data that is not migrated to OSS. Then, your client can read data from the data source based on the Location value in the 302 redirection request.
Page redirection
For example, you want to hide objects that start with specific prefixes and return a special page to requesters.
Page redirection for 404 or 500 errors
In the event of a 404 or 500 error, a preset page is displayed for requesters. This way, system errors are not fully exposed to requesters.
Use the OSS console
If a specified error occurs when a requester requests access to a bucket, you can specify the URL of the object in the origin and back-to-origin conditions to redirect the access to the origin. For example, you have the examplefolder directory in the root directory of the examplebucket bucket in the China (Hangzhou) region. You want to redirect a request for a non-existent object in the directory of the bucket to the examplefolder folder hosted at https://www.example.com/
.
Log on to the OSS console.
In the left-side navigation pane, click Buckets. On the Buckets page, find and click the desired bucket.
In the left-side navigation tree, choose .
On the Mirroring-based Back-to-origin page, click Create Rule.
In the Create Rule panel, set the required parameters and retain the default settings for other parameters.
Parameter
Description
Method
Select Redirect.
Condition
Select HTTP Status Code and set HTTP Status Code to 404.
Valid values of HTTP status codes: 400 to 599. For more information about HTTP status codes, see Overview.
Select Object Name Prefix and set the value to examplefolder/.
NoteFile Name Prefix and File Name Suffix are optional. When you configure multiple back-to-origin rules, you must set different file name prefixes or suffixes to differentiate back-to-origin rules.
Origin URL
Select Add Prefix or Suffix. Select https in the first box, enter www.example.com in the second box, and leave the other boxes empty.
Click OK.
The following content shows the access process after the preceding back-to-origin rule is configured:
A requester requests
https://examplebucket.oss-cn-hangzhou.aliyuncs.com/examplefolder/example.txt
for the first time.If the examplefolder/example.txt object does not exist in examplebucket, OSS returns HTTP 301 status code to the requester and provides
https://www.example.com/examplefolder/example.txt
for redirection.The requester accesses
https://www.example.com/examplefolder/example.txt
.
The following table describes the parameters you can configure for different scenarios.
Scenario
Parameters
An object name prefix is different from the prefix of the name of the object at the origin.
Select Replace or Delete File Prefix and enter a value in the third box for Origin URL. OSS replaces the value of Object Name Prefix with the value in the third box for Origin URL.
You can configure this parameter only if Object Name Prefix is configured.
You want to transfer the query string included in a request from OSS to the origin.
Select Transfer with Query String.
You want to change the HTTP status code for redirection.
The default HTTP status code for redirection is 301. You can modify it by selecting 302 or 307 from the Redirection Code drop-down list.
A redirect request is from Alibaba Cloud CDN.
Determine whether to select Source from Alibaba Cloud CDN.
When the redirection request is from Alibaba Cloud CDN: If you select Source from Alibaba Cloud CDN, CDN obtains the requested content based on the redirection rule. If you do not select Source from Alibaba Cloud CDN, CDN returns the URL for redirection to the client.