If you access data in a bucket that has no back-to-origin rules configured, 404 Not Found is returned. However, if you configure back-to-origin rules and configure the correct URL for the data, 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 product 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 the redirection feature to redirect object URLs and provide various services based on this feature.

You can configure a maximum of 20 back-to-origin rules, which are implemented in a sequence that they are set. For more information, see Manage back-to-origin configurations.

Procedure

  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 or Redirection.
    • In Mirroring 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.
    • In Redirection 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.

      By default, this option is required in Mirroring mode. You cannot modify this configuration. However, this option is optional in Redirection 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.
      Note This option is optional when you configure only one back-to-origin rule. When you configure multiple back-to-origin rules, make sure to differentiate the rules by specifying a different prefix for each of them.
    Origin URL Yes Configure the information about the origin URL.

    Directories with multiple levels must be separated with forward slashes (/). If you select Redirection, the directory name must end with a forward slash (/). The directory name cannot contain asterisks (*).

    • If you select Mirroring, 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: Enter the directory where the requested object is stored. Example: abc/123.
    • If you select Redirection, you must configure the processing rule based on the origin URL. The configurations of the first and second columns are similar to those when you select Mirroring.
      • 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 http://bucketname.oss-endpoint.com/image is automatically redirected to http://xx.com/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. If you set this parameter without setting File Name Prefix for Prerequisite, the specified prefix is added for the name of the object to which the access is redirected.
    Other Parameter No Transfer queryString: transfers the query string included in the request to OSS to the origin.
    3xx Response No (applicable only for mirroring) Follow Origin to Redirect Request: By default, the source 3xx redirection request is followed to obtain the resource and the resource is saved in OSS. If this option is not selected, OSS passes the 3xx response without obtaining the resource.
    Set Transmission Rule of HTTP Header No (applicable only for mirroring) 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.
    Redirection Code Yes (applicable only for redirection) You can select the redirection code from the drop-down list.

    Source from Alibaba Cloud CDN: Select this option if the origin is from Alibaba Cloud CDN.

    Examples of transmission rule configurations for HTTP headers are listed as follows.
    If the HTTP header in a request that is sent to OSS is as follows:
    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 as follows:
    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
  6. Click OK.