Description
The PUT Bucket website request is used to configure a static website for a bucket. You can configure it by passing in an XML format configuration file, with a file size limit of 64 KB.
You are advised to debug this API through Platform Management > Cloud API Management > API Explorer in the console on the operation side.
Note:
API Explorer provides capabilities such as online calling, signature verification, SDK code generation, and quick interface search. You can view the request content and return results of each call and automatically generate SDK call examples.
Request
Request Example
PUT /?website HTTP/1.1
Host: <BucketName-APPID>.<Endpoint>
Date: GMT Date
Content-Type: application/xml
Content-Length: Content Length
Content-MD5: MD5
Authorization: Auth String
[Request Body]
Note:
<BucketName-APPID>is the bucket name with APPID as the suffix, for example, examplebucket-1250000000.- Authorization: Auth String (For details, refer to Request Signature).
Request Parameters
This API has no request parameters.
Request Header
This API only uses common request headers. For details, see Common Request Headers documentation.
Request Body
Submit application/xml request data containing the complete bucket static website configuration information.
<WebsiteConfiguration>
<IndexDocument>
<Suffix>String</Suffix>
</IndexDocument>
<RedirectAllRequestsTo>
<Protocol>String</Protocol>
</RedirectAllRequestsTo>
<AutoAddressing>
<Status>Enabled|Disabled</Status>
</AutoAddressing>
<ErrorDocument>
<Key>String</Key>
<OriginalHttpStatus>Enabled|Disabled</OriginalHttpStatus>
</ErrorDocument>
<RoutingRules>
<RoutingRule>
<Condition>
<HttpErrorCodeReturnedEquals>Integer</HttpErrorCodeReturnedEquals>
</Condition>
<Redirect>
<Protocol>String</Protocol>
<ReplaceKeyWith>String</ReplaceKeyWith>
</Redirect>
</RoutingRule>
<RoutingRule>
<Condition>
<KeyPrefixEquals>String</KeyPrefixEquals>
</Condition>
<Redirect>
<Protocol>String</Protocol>
<ReplaceKeyPrefixWith>String</ReplaceKeyPrefixWith>
</Redirect>
</RoutingRule>
</RoutingRules>
</WebsiteConfiguration>
Specific node descriptions are as follows:
| Node Name (Keyword) | Parent Node | Description | Type | Required |
|---|---|---|---|---|
| WebsiteConfiguration | No | Contains all request information for the PUT Bucket website operation. | Container | No |
Container node WebsiteConfiguration contents:
| Node Name (Keyword) | Parent Node | Description | Type | Required |
|---|---|---|---|---|
| IndexDocument | WebsiteConfiguration | Index document configuration | Container | Yes |
| RedirectAllRequestsTo | WebsiteConfiguration | Redirect all request configuration | Container | No |
| AutoAddressing | WebsiteConfiguration | Used to configure whether to ignore file extensions. | Container | No |
| ErrorDocument | WebsiteConfiguration | Error document configuration | Container | No |
| RoutingRules | WebsiteConfiguration | Redirect rule configuration, with a maximum of 100 RoutingRules set. | Container | No |
Container node IndexDocument contents:
| Node Name (Keyword) | Parent Node | Description | Type | Required |
|---|---|---|---|---|
| Suffix | WebsiteConfiguration.IndexDocument | Specify the object key suffix for the index document. For example, specifying index.html means that when accessing the root directory of the bucket, the content of index.html will be automatically returned, or when accessing the article/ directory, the content of article/index.html will be automatically returned. |
String | Yes |
Container node RedirectAllRequestsTo contents:
| Node Name (Keyword) | Parent Node | Description | Type | Required |
|---|---|---|---|---|
| Protocol | WebsiteConfiguration.RedirectAllRequestsTo | Specify the target protocol for redirecting all requests, which can only be set to HTTPS. | String | Yes |
Container Node AutoAddressing Contents:
| Node Name (Keyword) | Parent Node | Description | Type | Required |
|---|---|---|---|---|
| Status | WebsiteConfiguration.AutoAddressing | Used to configure whether to ignore HTML file extensions, with optional values of Enabled or Disabled, defaulting to Disabled. | String | No |
Container node ErrorDocument contents:
| Node Name (Keyword) | Parent Node | Description | Type | Required |
|---|---|---|---|---|
| Key | WebsiteConfiguration.ErrorDocument | Specify the object key for the common error document. When an error occurs and does not match the error code redirection in the redirect rule, the content of this object key will be returned. | String | Yes |
| OriginalHttpStatus | WebsiteConfiguration.ErrorDocument | Used to configure the HTTP status code that triggers the error document, with optional values of Enabled or Disabled, defaulting to Enabled. | String | No |
Container node RoutingRules contents:
| Node Name (Keyword) | Parent Node | Description | Type | Required |
|---|---|---|---|---|
| RoutingRule | WebsiteConfiguration.RoutingRules | Single redirect rule configuration | Container | Yes |
Container node RoutingRules.RoutingRule contents:
| Node Name (Keyword) | Parent Node | Description | Type | Required |
|---|---|---|---|---|
| Condition | WebsiteConfiguration.RoutingRules.RoutingRule | Condition configuration for redirect rule | Container | Yes |
| Redirect | WebsiteConfiguration.RoutingRules.RoutingRule | Specific redirect target configuration for redirect rule | Container | Yes |
Container node RoutingRules.RoutingRule.Condition contents:
| Node Name (Keyword) | Parent Node | Description | Type | Required |
|---|---|---|---|---|
| HttpErrorCodeRetu rnedEquals |
WebsiteConfigura tion.RoutingRules. RoutingRule.Condition |
Specify the error code matching condition for the redirect rule, supporting only 4XX return codes, such as 403 or 404. | Integer | HttpErrorCodeReturnedEquals and KeyPrefixEquals are mutually exclusive. |
| KeyPrefixEquals | WebsiteConfigura tion.RoutingRules. RoutingRule.Condition |
Specify the object key prefix matching condition for the redirect rule. | String | HttpErrorCodeReturnedEquals and KeyPrefixEquals are mutually exclusive. |
Container node RoutingRules.RoutingRule.Redirect contents:
| Node Name (Keyword) | Parent Node | Description | Type | Required |
|---|---|---|---|---|
| Protocol | WebsiteConfigura tion.RoutingRules. RoutingRule.Redirect |
Specify the target protocol for the redirect rule, which can only be set to HTTPS. | String | No |
| ReplaceKeyWith | WebsiteConfigura tion.RoutingRules. RoutingRule.Redirect |
Specify the object key for the specific redirect target of the redirect rule, replacing the entire original request object key. | String | ReplaceKeyWith and ReplaceKeyPrefixWith are mutually exclusive. |
| ReplaceKeyPrefixWith | WebsiteConfigura tion.RoutingRules. RoutingRule.Redirect |
Specify the object key for the specific redirect target of the redirect rule, replacing the matched prefix portion of the original request. It can only be set when the Condition is KeyPrefixEquals. | String | ReplaceKeyWith and ReplaceKeyPrefixWith are mutually exclusive. |
Response
Response Headers
This API only returns the public response header. For details, see Common Response Headers documentation.
Response Body
The response body for this API is empty.
Error Code
This API follows unified error response and error codes. For details, please refer to the Error Codes document.
Practical Case
Request
PUT /?website HTTP/1.1
Host: <BucketName-APPID>.<Endpoint>
Date: Wed, 20 May 2020 09:33:38 GMT
Content-Type: application/xml
Content-Length: 1209
Content-MD5: VHzj4Uwb++HLyCJp7jUzWg==
Authorization: q-sign-algorithm=sha1&q-ak=AKID8A0fBVtYFrNm02oY1g1JQQF0c3JO****&q-sign-time=1589967218;1589974418&q-key-time=1589967218;1589974418&q-header-list=content-length;content-md5;content-type;date;host&q-url-param-list=website&q-signature=4666493555640e834a879c78afaa4fd9b16a****
Connection: close
<WebsiteConfiguration>
<IndexDocument>
<Suffix>index.html</Suffix>
</IndexDocument>
<RedirectAllRequestsTo>
<Protocol>https</Protocol>
</RedirectAllRequestsTo>
<ErrorDocument>
<Key>pages/error.html</Key>
</ErrorDocument>
<RoutingRules>
<RoutingRule>
<Condition>
<HttpErrorCodeReturnedEquals>403</HttpErrorCodeReturnedEquals>
</Condition>
<Redirect>
<Protocol>https</Protocol>
<ReplaceKeyWith>pages/403.html</ReplaceKeyWith>
</Redirect>
</RoutingRule>
<RoutingRule>
<Condition>
<HttpErrorCodeReturnedEquals>404</HttpErrorCodeReturnedEquals>
</Condition>
<Redirect>
<ReplaceKeyWith>pages/404.html</ReplaceKeyWith>
</Redirect>
</RoutingRule>
<RoutingRule>
<Condition>
<KeyPrefixEquals>assets/</KeyPrefixEquals>
</Condition>
<Redirect>
<ReplaceKeyWith>index.html</ReplaceKeyWith>
</Redirect>
</RoutingRule>
<RoutingRule>
<Condition>
<KeyPrefixEquals>article/</KeyPrefixEquals>
</Condition>
<Redirect>
<Protocol>https</Protocol>
<ReplaceKeyPrefixWith>archived/</ReplaceKeyPrefixWith>
</Redirect>
</RoutingRule>
</RoutingRules>
</WebsiteConfiguration>
Response
HTTP/1.1 200 OK
Content-Length: 0
Connection: close
Date: Wed, 20 May 2020 09:33:38 GMT
x-cos-request-id: NWVjNGY5NzJfOThjMjJhMDlfMjg5Ml8yYzNi****