Updated on 2024-10-24 GMT+08:00

Redirecting Requests

Redirection Overview

When using static website hosting, you can configure redirection to redirect specific or all requests.

If the structure, address, or file name extension of a website is changed, users will fail to access the website using the old address (such as the address saved in the folder of favorites), and the 404 error message is returned. In this case, you can configure redirection for the website to redirect user access requests to a specified page rather than a 404 error page.

Typical scenarios include:

  • Redirecting all requests to another website.
  • Redirecting specific requests based on redirection rules.

Prerequisites

Web page files required for static website hosting have been uploaded to the specified bucket.

The static website files hosted in the bucket are accessible to all users.

Static web page files in the Archiveor Deep Archive storage class have been restored. For more information, see Restoring Archive or Deep Archive Objects.

Procedure

  1. In the navigation pane of OBS Console, choose Object Storage.
  2. In the bucket list, click the bucket you want to operate. The Objects page is displayed.
  3. In the navigation pane, choose Overview.
  4. In the Basic Configurations area, click Static Website Hosting. The Static Website Hosting page is displayed.

    Alternatively, you can choose Basic Configurations > Static Website Hosting from the navigation pane on the left.

  5. Click Configure Static Website Hosting. The Configure Static Website Hosting dialog box is displayed.
  6. Enable Status.
  7. Set Hosting Type to Redirect requests, as shown in Figure 1. In the text box of Redirect To, enter the bucket's access domain name or URL.

    Figure 1 Configuring redirection

  8. Click OK.
  9. In the bucket list, click the bucket to which requests for the static website are redirected.
  10. (Optional) If the static website files in the bucket are not accessible to everyone, perform this step. If they are already accessible to everyone, skip this step.

    To grant required permissions, see Granting All Accounts Read Permission for Specified Objects.

    If the bucket contains only static website files, configure the Object Read-Only policy for the bucket, so that all files in it are publicly accessible.

    1. Choose Permissions > Bucket Policies.
    2. Click Create.
    3. Configure bucket policy information.
      Figure 2 Granting the Object Read-Only permission

      Table 1 Parameters for configuring a public read policy

      Parameter

      Description

      Configuration method

      Visual Editor and JSON are available. The visual editor is used here. For details about configurations in the JSON view, see Creating a Custom Bucket Policy (JSON View).

      Policy Name

      Enter a custom policy name.

      Policy content

      Effect

      Select Allow.

      Principals

      Select All accounts.

      Resources

      • Select Specified objects.
      • Set the resource path to * (indicating all objects in the bucket).

      Actions

      • Choose Use a template.
      • Select Object Read-Only.
    4. Click Create. The bucket policy is created.

  11. Verification: Input the access domain name of the bucket in the web browser and press Enter. The bucket or URL to which requests are redirected will be displayed.

    In some conditions, you may need to clear the browser cache before the expected results are displayed.