Configuring Static Website Hosting for a Bucket
Function
OBS allows you to store static web page resources such as HTML web pages, flash files, videos, and audios in 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. You can use this API to configure or update the website configuration of a bucket. For more information about static website hosting, see Static Website Hosting.
Constraints
- Avoid using periods (.) in a bucket name, or accessing the bucket over HTTPS may result in certificate verification failures on the client.
- The body of the request used to configure static website hosting must not exceed 10 KB.
Authorization
To call this API, you must be the bucket owner or have the permission to configure static website hosting for a bucket. You are advised to use IAM or bucket policies for authorization. For details about OBS authorization methods, see Differences Between OBS Permissions Control Methods.
- If you use IAM for authorization, you need to use either role/policy-based authorization or identity policy-based authorization and configure the required permissions:
- If you use role/policy-based authorization (IAM v3 APIs in the old IAM version), you must have the obs:bucket:PutBucketWebsite permission. For details, see Creating a Custom IAM Policy.
- If you use identity policy-based authorization (IAM v5 APIs in the new IAM version), you must have the obs:bucket:putBucketWebsite permission, as shown in the following table. For details, see Creating a Custom IAM Identity Policy.
Action
Access Level
Resource Type (*: Required)
Dependencies
obs:bucket:putBucketWebsite
Write
bucket *
-
-
-
- obs:EpochTime
- obs:SourceIp
- obs:TlsVersion
- obs:CustomDomain
- If you use bucket policies for authorization, you must have the obs:bucket:PutBucketWebsite permission. For details, see Creating a Custom Bucket Policy.
URI
PUT /
Calling Method
For details, see Calling APIs. Before calling this API, calculate the API signature and add it to the request.
You can debug this API in API Explorer.
Request Syntax
1 2 3 4 5 6 7 8 9 10 | PUT /?website HTTP/1.1 Host: bucketname.obs.region.myhuaweicloud.com Content-Length: length Date: date Authorization: authorization <WebsiteConfiguration> <RedirectAllRequestsTo> <HostName>hostName</HostName> </RedirectAllRequestsTo> </WebsiteConfiguration> |
URI Parameters
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| website | Yes | String | Definition An identifier that marks this API as related to bucket website configuration. Constraints When calculating the signature, add /BucketName/?website to CanonicalizedResource. For details, see Using an Authorization Header. Range website Default Value N/A |
Request Headers
This request uses common headers. For details, see Table 3.
Request Body
This request contains elements to specify the website configuration in XML format.
- To redirect all requests sent to the bucket, add the website elements as described in Table 2.
Table 2 Elements for redirecting all website requests Parameter
Type
Mandatory
Description
WebsiteConfiguration
Container
Yes
Definition
Root node for the website configuration.
Constraints
N/A
Range
N/A
Default Value
N/A
RedirectAllRequestsTo
Container
Yes
Definition
Describes the redirection behavior for all requests to this bucket. If this element is present, no other siblings are allowed. WebsiteConfiguration is the parent node of RedirectAllRequestsTo.
Constraints
N/A
Range
N/A
Default Value
N/A
HostName
String
Yes
Definition
Name of the host where requests will be redirected. RedirectAllRequestsTo is the parent node of HostName.
Constraints
Do not include the http:// or https:// prefix.
Range
A valid domain name or host name without the protocol prefix.
Default Value
N/A
Protocol
String
No
Definition
HTTP or HTTPS protocol used for redirecting requests. The default protocol is HTTP. RedirectAllRequestsTo is the parent node of Protocol.
Constraints
N/A
Range
http or https
Default Value
N/A
- To configure redirection rules, add the website elements as described in Table 3.
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| WebsiteConfiguration | Yes | Container | Definition Root node for the website configuration. Constraints N/A Range N/A Default Value N/A |
| IndexDocument | Yes | Container | Definition Parent node for Suffix. It is the container of the homepage configuration. Parent: WebsiteConfiguration Child: Suffix Constraints If RedirectAllRequestsTo is not included, IndexDocument must be used. Range N/A Default Value N/A |
| Suffix | Yes | String | Definition Suffix that is appended to the requested directory. For example, if the suffix is index.html and samplebucket/images/ is requested, the returned data will be the content under the object name images/index.html in the samplebucket bucket. Parent: IndexDocument Constraints Suffix cannot be empty or contain slashes (/). Range A non-empty string containing no more than 1,024 characters Default Value N/A |
| ErrorDocument | No | Container | Definition Parent node of Key. It is the container for the error page configuration when a 4XX error occurs. Parent: WebsiteConfiguration Constraints The value cannot be empty and can contain a maximum of 1,024 bytes of UTF-8 encoded data. Range N/A Default Value N/A |
| Key | No | String | Definition Object name that is used when a 4XX error occurs. This element identifies the page that is returned when a 4XX error occurs. If ErrorDocument is included, ErrorDocument is the parent node of Key. Parent: ErrorDocument Constraints The object must exist in the bucket. Range The object name must be 4 to 1,024 characters long. Default Value N/A |
| RoutingRules | No | Container | Definition Parent node of Routing. It is the container for redirection rules. Parent: WebsiteConfiguration Constraints There should be at least one RoutingRule. Range N/A Default Value N/A |
| RoutingRule | Yes | Container | Definition A redirection rule. A redirection rule contains a Condition and a Redirect. When the Condition is matched, Redirect takes effect. Parent: RoutingRules is the parent node of RoutingRule. There should be at least one RoutingRule. Constraints N/A Range N/A Default Value N/A |
| Condition | No | Container | Definition A condition that must be met for the specified redirection to apply. Parent: RoutingRule Constraints There should be at least one subparameter (KeyPrefixEquals or HttpErrorCodeReturnedEquals). Range N/A Default Value N/A |
| Redirect | Yes | Container | Definition Redirection information. You can redirect requests to another host, to another web page, or with another protocol. You can specify different status codes when events or errors occur. Parent: RoutingRule Constraints N/A Range N/A Default Value N/A |
Response Syntax
1 2 3 | HTTP/1.1 status_code Date: date Content-Length: length |
Response Headers
This response uses common headers. For details, see Table 1.
Response Body
This response contains no elements.
Error Responses
No special errors. You can find all errors in Error Code Overview.
Sample Request: Redirecting All Requests for a Bucket to Another Bucket or URL
1 2 3 4 5 6 7 8 9 10 11 12 13 | PUT /?website HTTP/1.1 User-Agent: curl/7.29.0 Host: examplebucket.obs.region.myhuaweicloud.com Accept: */* Date: Wed, 01 Jul 2015 03:40:29 GMT Authorization: OBS H4IPJX0TQTHTHEBQQCEC:pUK7Yp0yebnq4P6gqzVjoS7whoM= Content-Length: 194 <WebsiteConfiguration xmlns="http://obs.ap-southeast-1.myhuaweicloud.com/doc/2015-06-30/"> <RedirectAllRequestsTo> <HostName>www.huaweicloud.com</HostName> </RedirectAllRequestsTo> </WebsiteConfiguration> |
Sample Response: Redirecting All Requests for a Bucket to Another Bucket or URL
1 2 3 4 5 6 | HTTP/1.1 200 OK Server: OBS x-obs-request-id: BF2600000164360D144670B9D02AABC6 x-obs-id-2: 32AAAQAAEAABSAAgAAEAABAAAQAAEAABCSItqMZ/AoFUX97l1xx8s67V3cCQtXWk Date: Wed, 01 Jul 2015 03:40:29 GMT Content-Length: 0 |
Sample Request: Configuring a Bucket to Host a Static Website
PUT /?website HTTP/1.1
Authorization: OBS H4IPJX0TQTHTHEBQQCEC:iqSPeUBl66PwXDApxjRKk6hlcN4=
User-Agent: curl/7.29.0
Host: examplebucket.obs.region.myhuaweicloud.com
Date: Wed, 01 Jul 2015 02:37:22 GMT
Content-Type: application/xml
<WebsiteConfiguration xmlns="http://obs.ap-southeast-1.myhuaweicloud.com/doc/2015-06-30/">
<IndexDocument>
<Suffix>index.html</Suffix>
</IndexDocument>
<ErrorDocument>
<Key>SomeErrorDocument.html</Key>
</ErrorDocument>
</WebsiteConfiguration> Sample Response: Configuring a Bucket to Host a Static Website
HTTP/1.1 200 OK x-obs-id-2: 32AAAQAAEAABSAAgAAEAABAAAQAAEAABCSfxlr+FrXuJzYpLod1lrLK45tVx+GPR x-obs-request-id: 0000018A39F07D0DD3888442DC29719E Server: OBS Content-Length: 0 Date: Wed, 01 Jul 2015 02:37:22 GMT
Sample Request: Configuring a Bucket to Host a Static Website, with an Optional Redirection Rule Specified
PUT /?website HTTP/1.1
Authorization: OBS H4IPJX0TQTHTHEBQQCEC:iqSPeUBl66PwXDApxjRKk6hlcN4=
User-Agent: curl/7.29.0
Host: examplebucket.obs.region.myhuaweicloud.com
Date: Wed, 01 Jul 2015 02:37:22 GMT
Content-Type: application/xml
<WebsiteConfiguration xmlns="http://obs.ap-southeast-1.myhuaweicloud.com/doc/2015-06-30/">
<IndexDocument>
<Suffix>index.html</Suffix>
</IndexDocument>
<ErrorDocument>
<Key>Error.html</Key>
</ErrorDocument>
<RoutingRules>
<RoutingRule>
<Condition>
<KeyPrefixEquals>docs/</KeyPrefixEquals>
</Condition>
<Redirect>
<ReplaceKeyPrefixWith>documents/</ReplaceKeyPrefixWith>
</Redirect>
</RoutingRule>
</RoutingRules>
</WebsiteConfiguration> Sample Response: Configuring a Bucket to Host a Static Website, with an Optional Redirection Rule Specified
HTTP/1.1 200 OK x-obs-id-2: 32AAAQAAEAABSAAgAAEAABAAAQAAEAABCSxixo46vLYhGrY/zwgqlM0fMNpeFthi x-obs-request-id: 0000018A39F2E328D3888F46DB9BB5A2 Server: OBS Content-Length: 0 Date: Wed, 01 Jul 2015 02:37:22 GMT
Sample Request: Configuring a Bucket to Host a Static Website and Redirecting Errors
PUT /?website HTTP/1.1
Authorization: OBS H4IPJX0TQTHTHEBQQCEC:iqSPeUBl66PwXDApxjRKk6hlcN4=
User-Agent: curl/7.29.0
Host: examplebucket.obs.region.myhuaweicloud.com
Date: Wed, 01 Jul 2015 02:37:22 GMT
Content-Type: application/xml
<WebsiteConfiguration xmlns="http://obs.ap-southeast-1.myhuaweicloud.com/doc/2015-06-30/">
<IndexDocument>
<Suffix>index.html</Suffix>
</IndexDocument>
<ErrorDocument>
<Key>Error.html</Key>
</ErrorDocument>
<RoutingRules>
<RoutingRule>
<Condition>
<HttpErrorCodeReturnedEquals>404</HttpErrorCodeReturnedEquals>
</Condition>
<Redirect>
<HostName>www.huaweicloud.com</HostName>
<ReplaceKeyPrefixWith>report-404/</ReplaceKeyPrefixWith>
</Redirect>
</RoutingRule>
</RoutingRules>
</WebsiteConfiguration> Sample Response: Configuring a Bucket to Host a Static Website and Redirecting Errors
HTTP/1.1 200 OK x-obs-id-2: 32AAAQAAEAABSAAgAAEAABAAAQAAEAABCS/xBBLGZwRUiL439eWMw1v/vphFB6JY x-obs-request-id: 0000018A3A06C048D38610C04366B2F5 Server: OBS Content-Length: 0 Date: Wed, 01 Jul 2015 02:37:22 GMT
Sample Request: Configuring a Bucket to Host a Static Website and Redirecting Requests for Folders to Another Page
PUT /?website HTTP/1.1
Authorization: OBS H4IPJX0TQTHTHEBQQCEC:iqSPeUBl66PwXDApxjRKk6hlcN4=
User-Agent: curl/7.29.0
Host: examplebucket.obs.region.myhuaweicloud.com
Date: Wed, 01 Jul 2015 02:37:22 GMT
Content-Type: application/xml
<WebsiteConfiguration xmlns="http://obs.ap-southeast-1.myhuaweicloud.com/doc/2015-06-30/">
<IndexDocument>
<Suffix>index.html</Suffix>
</IndexDocument>
<ErrorDocument>
<Key>Error.html</Key>
</ErrorDocument>
<RoutingRules>
<RoutingRule>
<Condition>
<KeyPrefixEquals>images/</KeyPrefixEquals>
</Condition>
<Redirect>
<ReplaceKeyWith>errorpage.html</ReplaceKeyWith>
</Redirect>
</RoutingRule>
</RoutingRules>
</WebsiteConfiguration> Sample Response: Configuring a Bucket to Host a Static Website and Redirecting Requests for Folders to Another Page
HTTP/1.1 200 OK x-obs-id-2: 32AAAQAAEAABSAAgAAEAABAAAQAAEAABCSLjAKDDyha8LY/HcoFNfbLBeAKCAYcv x-obs-request-id: 0000018A3A09D30CD306902FC7572429 Server: OBS Content-Length: 0 Date: Wed, 01 Jul 2015 02:37:22 GMT
Using SDKs to Call APIs
You are advised to use OBS SDKs to call APIs. SDKs encapsulate APIs to simplify development. You can call SDK API functions to access OBS without manually calculating signatures.
Helpful Links
- For more information about static website hosting, see Static Website Hosting.
- For details about the billing items involved in API operations, see Billing Items.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot