PUT Bucket Website

OBS allows you to store static web page resources such as HTML web pages, flash files, video files, and audio files to a bucket. When a client accesses these resources from the website endpoint of the bucket, the browser can directly resolve and present the resources to the client. This operation can be used to:

  • Redirect all requests sent to a website endpoint.
  • Add routing rules that redirect only specific requests.

You can perform this operation to create or update the website configuration of a bucket.

Only users granted the s3:PutBucketWebsite permission can set the bucket website configuration. By default, only the bucket owner can set the bucket website configuration. The bucket owner can allow other users to set the bucket website configuration by granting them the permission.

NOTE:

Avoid using periods (.) in the target bucket name. Otherwise, the client may fail to authenticate the certificate when you use HTTPS for access.

Request Syntax

PUT /?website HTTP/1.1
Host: bucketname.obs.cn-north-1.myhwclouds.com
Content-Length: length
Date: date
Authorization: authorization

<WebsiteConfiguration>
    <RedirectAllRequestsTo>
        <HostName>hostName</HostName>
    </RedirectAllRequestsTo>
</WebsiteConfiguration>

Request Parameters

This request contains no parameter.

Request Headers

This request uses common headers. For details, see Common Request Headers.

Request Elements

This request contains elements to specify the website configuration in XML format.

  • To redirect all website requests sent to the bucket's website endpoint, add the elements as described in Table 1.
Table 1 Elements for redirecting all website requests

Element

Description

Required or Optional

WebsiteConfiguration

Indicates the root element for the website configuration.

Type: element

Ancestor: none

Required

RedirectAllRequestsTo

Describes the redirection behavior for every request to this bucket's website endpoint. If this element is present, no other siblings are allowed.

Type: element

Ancestor: WebsiteConfiguration

Required

HostName

Indicates the name of the host where requests will be redirected.

Type: string

Ancestor: RedirectAllRequestsTo

Required

Protocol

Indicates the protocol (HTTP or HTTPS) used in redirecting requests. The default protocol is HTTP.

Type: string

Ancestor: RedirectAllRequestsTo

Optional

  • To add routing rules that describe conditions for redirecting requests, add the elements as described in Table 2.
Table 2 Elements for adding rules that redirect requests

Element

Description

Required or Optional

WebsiteConfiguration

Indicates the root element for the website configuration.

Type: element

Ancestor: none

Required

IndexDocument

Suff element.

Type: element

Ancestor: WebsiteConfiguration

Required

Suffix

Indicates a suffix that is appended to a request initiated for a directory on the website endpoint. For example, if the suffix is index.html and you request samplebucket/images/, the data that is returned will be for the object with the key name images/index.html in the samplebucket bucket. The suffix cannot be empty or contain slashes (/).

Type: string

Ancestor: IndexDocument

Required

ErrorDocument

Key element.

Type: element

Ancestor: WebsiteConfiguration

Optional

Key

Indicates the object key that is used when a 4xx error occurs. This element identifies the page that is returned when a 4xx error occurs.

Type: string

Ancestor: ErrorDocument

Condition: Required when ErrorDocument is specified.

Optional

RoutingRules

Routin element.

Type: element

Ancestor: WebsiteConfiguration

Optional

RoutingRule

Indicates the element for a routing rule that identifies a condition and a redirect applicable when the condition is met.

Type: element

Ancestor: RoutingRules

At least the RoutingRule element is required.

Required

Condition

Indicates the element for describing a condition that must be met for the specified redirect to apply.

Type: element

Ancestor: RoutingRule

Optional

KeyPrefixEquals

Indicates the object key name prefix when the redirection is applied.

For example:

  • To redirect the request for object ExamplePage.html, the key prefix is set to ExamplePage.html.

Type: string

Ancestor: Condition

Condition: Required when the ancestor element Condition is specified and sibling HttpErrorCodeReturnedEquals is not specified. If two conditions are specified, both conditions must be true for the redirection to be applied.

Optional

HttpErrorCodeReturnedEquals

Indicates the HTTP error code returned when the redirection is applied. The specified redirect is applied only when the error code returned equals this value.

For example:

  • If you want to redirect to NotFound.html when HTTP error code 404 is returned, set HttpErrorCodeReturnedEquals to 404 in Condition and ReplaceKeyWith to NotFound.html in Redirect.

Type: string

Ancestor: Condition

Condition: Required when ancestor element Condition is specified and sibling KeyPrefixEquals is not specified. If multiple conditions are specified, the redirection takes effect only after all conditions are met.

Optional

Redirect

Indicates the element for redirection information. You can redirect requests to another host, to another web page, or with another protocol. You can specify an error code to be returned after an error.

Type: element

Ancestor: RoutingRule

Required

Protocol

Indicates the protocol used in the redirection request.

Type: string

Ancestor: Redirect

Valid values: http, https

Condition: Not required if one of the siblings is present.

Optional

HostName

Indicates the host name used in the redirection request.

Type: string

Ancestor: Redirect

Condition: Not required if one of the siblings is present.

Optional

ReplaceKeyPrefixWith

Indicates the object key prefix used in the redirection request.

For example:

  • To redirect all requests for (objects under) docs to (objects under) documents, set KeyPrefixEquals to docs in Condition and ReplaceKeyPrefixWith to documents in Redirect.

Type: string

Ancestor: Redirect

Condition: Not required if one of the siblings is present. Can be present only if ReplaceKeyWith is not provided.

Optional

ReplaceKeyWith

Indicates the object key used in the redirection request. For example, redirect requests to error.html.

Type: string

Ancestor: Redirect

Condition: Not required if one of the siblings is present. Can be present only if ReplaceKeyPrefixWith is not provided.

Optional

HttpRedirectCode

Indicates the HTTP status code returned after the redirection request.

Type: string

Ancestor: Redirect

Condition: Not required if one of the siblings is present.

Optional

Response Syntax

HTTP/1.1 status_code
Date: date
Content-Length: length

Response Headers

This response uses common headers. For details, see Common Response Headers.

Response Elements

This response contains no element.

Error Responses

No special error responses are returned. For details about error responses, see Table 1.

Registration