If you access data in a bucket that has no back-to-origin rules configured and the data does not exist, 404 Not Found is returned. However, if you configure back-to-origin rules and the back-to-origin URL, you can obtain the data based on the back-to-origin rules.

Background information

Back-to-origin supports the mirroring and redirection modes. You can configure back-to-origin rules for online data migration and specific request redirection.
  • Mirroring

    After mirroring-based back-to-origin rules are configured for a bucket, you can obtain an object in the bucket based on the rules when the requested object is not found. For example, when you perform the GetObject operation on an object and the object is not found, OSS retrieves the object based on the origin URL, returns the object, and writes the object to OSS. Mirroring-based back-to-origin rules are used to seamlessly migrate data to OSS. This feature allows you to migrate any service that already runs on a user-created origin or in another cloud service to OSS without interrupting services.

  • Redirection

    After redirection-based back-to-origin rules are configured for a bucket, you can obtain an object in the bucket based on the rules when the requested object is not found. For example, when you perform the GetObject operation on an object and the object is not found, OSS redirects the request to the origin URL, and then a browser or client returns the content from the origin. You can use this feature to redirect objects and develop various services based on redirection.

You can configure up to 20 back-to-origin rules, which are implemented in a sequence that they are configured. For more information, see Manage back-to-origin configurations.
Notice Back-to-origin rules and versioning cannot be configured for a bucket at the same time.

Configure a mirroring-based back-to-origin rule

  1. Log on to the OSS console.
  2. Click Buckets, and then click the name of the target bucket.
  3. Choose Basic Settings > Back-to-Origin.
  4. Click Configure. Click Create Rule.
  5. In the Create Rule dialog box that appears, configure a back-to-origin rule.
    Parameter Required Description
    Mode Yes Select Mirroring. In this mode, when a requested object cannot be found in OSS, OSS automatically retrieves the object from the origin, stores it in OSS, and returns the content to the requester.
    Prerequisite Yes Configure the conditions that trigger the back-to-origin rule. A rule is triggered only when all conditions are met.
    • HTTP Status Code: The back-to-origin rule is triggered when the specified HTTP status code is returned. The default HTTP status code is 404, which indicates that the rule is triggered when the requested object is not found in OSS and HTTP status code 404 is returned. By default, this option is selected when you select the Mirroring mode.
    • File Name Prefix: The back-to-origin rule is triggered when the name of the requested object contains the specified prefix. For example, when this parameter is set to abc/, the back-to-origin rule is triggered when you access http://bucketname.oss-endpoint.com/abc/image.jpg.
    • File Name Suffix: The back-to-origin rule is triggered when the name of the requested object contains the specified suffix. For example, when this parameter is set to .jpg, the back-to-origin rule is triggered when you access http://bucketname.oss-endpoint.com/image.jpg.
    Note File Name Prefix and File Name Suffix are optional when you configure only one back-to-origin rule. When you configure multiple back-to-origin rules, you must differentiate the rules by specifying a different prefix or suffix for each of them.
    Replace or Delete File Prefix No You can configure this parameter after you select and configure File Name Prefix. When OSS sends a request to the origin, the content of File Name Prefix is replaced with that of Replace or Delete File Prefix.

    Example: You want to store the object obtained from the origin to the Mirror folder under the root directory of the bucket. If the name of the target object is path/test/photo.jpg, set File Name Prefix to mirror/, Replace or Delete File Prefix to test/, and the third column of Origin URL to path. In this case, when you access bucketname.oss-endpoint.com/mirror/photo.jpg, if photo.jpg does not exist, OSS sends the Origin URL/path/test/photo.jpg request to obtain this object. If the object is obtained from the origin, OSS stores this object in the mirror/ folder and returns the object to you.

    Origin URL Yes Configure the information about the origin URL.
    • First column: Select HTTP or HTTPS based on the protocol used by the origin.
    • Second column: Enter the domain name or IP address of the origin.
      Note You can only enter IP addresses of origins that can be directly accessed by using IP addresses.
    • Third column: Enter the directory where the requested object is stored. Directories with multiple levels must be separated with forward slashes (/). Example: abc/123.
    MD5 Verification No If this option is selected, the MD5 hash of the object obtained from the origin is checked. When the response contains a Content-MD5 hash, OSS checks whether the MD5 hash of the object matches the Content-MD5 hash. If they do not match, OSS does not save the object by using mirroring-based back-to-origin.
    Other Parameter No If this option is selected, the query string included in the request to OSS is transferred to the origin.
    3xx Response No If this option is selected, OSS follows the 3xx redirection request to obtain the resource and stores the resource in buckets. If this option is not selected, OSS passes the 3xx response without obtaining the resource.
    Set Transmission Rule of HTTP Header No You can configure the transmission rule for HTTP headers to customize transmission actions, such as passthrough, filtering, or modification. For more information, see the following examples of transmission rule configurations for HTTP headers.
    Examples of transmission rule configurations for HTTP headers:
    If the HTTP header in a request that is sent to OSS is:
    GET /object
    host : bucket.oss-cn-hangzhou.aliyuncs.com
    aaa-header : aaa
    bbb-header : bbb
    ccc-header : 111
    then after the mirroring-based back-to-origin rule is triggered, the request that OSS sends to the origin is:
    GET /object
    host : source.com
    aaa-header : aaa
    ccc-header : ccc                       
    Note Transmission rules do not support the following HTTP headers:
    • Headers with the following prefixes:
      • x-oss-
      • oss-
      • x-drs-
    • All standard HTTP headers such as:
      • content-length
      • authorization2
      • authorization
      • range
      • date

Configure a redirection-based back-to-origin rule

  1. Log on to the OSS console.
  2. Click Buckets, and then click the name of the target bucket.
  3. Choose Basic Settings > Back-to-Origin.
  4. Click Configure. Click Create Rule.
  5. In the Create Rule dialog box that appears, configure a redirection-based back-to-origin rule.
    Parameter Required Description
    Mode Yes Select Redirection. In this mode, OSS redirects requests that meet the prerequisites to the origin URL over HTTP, and then a browser or client returns the content from the origin to the requester.
    Prerequisite Yes Configure the conditions that trigger the back-to-origin rule. A rule is triggered only when all conditions are met.
    • HTTP Status Code: The back-to-origin rule is triggered when the specified HTTP status code is returned. The default HTTP status code is 404, which indicates that the rule is triggered when the requested object is not found in OSS and HTTP status code 404 is returned.
    • File Name Prefix: The back-to-origin rule is triggered when the name of the requested object contains the specified prefix. For example, when this parameter is set to abc/, the back-to-origin rule is triggered when you access http://bucketname.oss-endpoint.com/abc/image.jpg.
    • File Name Suffix: The back-to-origin rule is triggered when the name of the requested object contains the specified suffix. For example, when this parameter is set to .jpg, the back-to-origin rule is triggered when you access http://bucketname.oss-endpoint.com/image.jpg.
    Note File Name Prefix and File Name Suffix are optional when you configure only one back-to-origin rule. When you configure multiple back-to-origin rules, you must differentiate the rules by specifying a different prefix or suffix for each of them.
    Replace or Delete File Prefix No You can configure this parameter after you select and configure File Name Prefix. When OSS sends a request to the origin, the content of File Name Prefix is replaced with that of Replace File Name Prefix.
    Note If this option is selected, Origin URL can be configured only to Replace File Name Prefix.
    Origin URL Yes Configure the information about the origin URL. You must configure the back-to-origin rule based on the origin URL.
    Configure the origin URL as follows:
    • First column: Select HTTP or HTTPS based on the protocol used by the origin.
    • Second column: Enter the domain name or IP address of the origin.
      Note You can only enter IP addresses of origins that can be directly accessed by using IP addresses.
    • Third column: Configure the redirection-based back-to-origin rule based on the prefix and suffix rule.
      • Add Prefix or Suffix: Add a prefix or suffix to the redirected URL. The prefix is configured in the third column. The suffix is configured in the fourth column.

        You can select this option to configure correct information for the redirected URL when the URL of the requested data does not have a prefix or suffix. If you set the prefix to 123/ and the suffix to .jpg, access to bucketname.oss-endpoint.com/image is automatically redirected to Origin URL/123/image.jpg.

      • Redirect to Fixed URL: Access to the requested object is redirected to a specified object. The object address is specified in the third column. Example: abc/myphoto.jpg.
        Note You can also set a website URL. For example, if you set the URL to https://www.aliyun.com/index.html, access to the bucket is redirected to the Alibaba Cloud homepage.
      • Replace File Name Prefix: If you set this parameter and File Name Prefix for Prerequisite, the prefix in the name of the object to which the access is redirected is replaced with that of the third column. If you set this parameter without setting File Name Prefix for Prerequisite, the specified prefix is added to the name of the object to which the access is redirected.

      Directories with multiple levels must be separated with forward slashes (/). The directory name must end with a forward slash (/). The directory name cannot contain asterisks (*).

    Other Parameter No If this option is selected, the query string included in the request to OSS is transferred to the origin.
    Redirection Code Yes You can select the redirection code from the drop-down list. Select Source from Alibaba Cloud CDN if the redirection request is from Alibaba Cloud CDN.
  6. Click OK.