This section describes how to configure static website hosting for buckets and use bucket domain names to access static websites.
The static website hosting takes effect within two minutes after its configuration is complete.
Web page files of the static website have been uploaded to a bucket.
The static website files hosted in the bucket are accessible to anonymous users.
If the web page files are in the Cold storage class, restore them first. For more information, see Restoring a Cold File Stored in OBS.
Authorize anonymous users the permission to read files on the static website. For details, see Authorizing Access Permissions to Anonymous Users.
If the bucket contains only static website files, configure the Public Read policy for the bucket so that all files in it can be accessed publicly.
Alternatively, you can choose Basic Configurations > Static Website Hosting from the navigation pane on the left.
OBS only allows files such as index.html in the root directory of a bucket to function as the default homepage. That is to say, do not set the default homepage with a multi-level directory structure (for example, /page/index.html).
A redirection rule is compiled in the JSON or XML format. Each rule contains a Condition and a Redirect. The parameters are described as follows:
Container |
Key |
Description |
---|---|---|
Condition |
KeyPrefixEquals |
Object name prefix on which the redirection rule takes effect. When a request is sent for accessing an object, the redirection rule takes effect if the object name prefix matches the value specified for this parameter. For example, to redirect the request for object ExamplePage.html, set the KeyPrefixEquals to ExamplePage.html. |
HttpErrorCodeReturnedEquals |
HTTP error codes upon which the redirection rule takes effect. The specified redirection is applied only when the error code returned equals the value specified for this parameter. For example, if you want to redirect requests to NotFound.html when HTTP error code 404 is returned, set HttpErrorCodeReturnedEquals to 404 in Condition, and set ReplaceKeyWith to NotFound.html in Redirect. |
|
Redirect |
Protocol |
Protocol used for redirection The value can be http or https. If this parameter is not specified, the default value http is used. |
HostName |
Host name to which the redirection is pointed. If this parameter is not specified, the request is redirected to the host from which the original request is initiated. |
|
ReplaceKeyPrefixWith |
Object name prefix on which the redirection rule takes effect |
|
ReplaceKeyWith |
Object name on which the redirection rule takes effect |
|
HttpRedirectCode |
HTTP status code returned to the redirection request. The default value is 301, indicating that requests are permanently redirected to the location specified by Redirect. You can also set this parameter based on your service needs. |
Example of setting a redirection rule
[ { "Condition": { "KeyPrefixEquals": "folder1/" }, "Redirect":{ "Protocol": "https", "HostName": "www.example.com", "ReplaceKeyPrefixWith": "target.html" } } ]
[ { "Condition": { "KeyPrefixEquals": "folder2/" }, "Redirect":{ "ReplaceKeyPrefixWith": "folder/" } } ]
[ { "Condition": { "KeyPrefixEquals": "folder.html" }, "Redirect":{ "ReplaceKeyWith": "folderdeleted.html" } } ]
[ { "Condition": { "HttpErrorCodeReturnedEquals": "404" }, "Redirect":{ "HostName": "www.example.com", "ReplaceKeyPrefixWith": "report-404/" } } ]
After the static website hosting is effective in OBS, you can access the static website by using the URL provided by OBS.
In some conditions, you may need to clear the browser cache before the expected results are displayed.