The PutBucketWebsite interface is used to set a bucket to the static website hosting mode.

Request syntax

PUT /? website HTTP/1.1
Date: GMT Date
Content-Length:ContentLength
Content-Type: application/xml
Host: BucketName.oss-cn-hangzhou.aliyuncs.com
Authorization: SignatureValue

<? xml version="1.0" encoding="UTF-8"? >
<WebsiteConfiguration>
    <IndexDocument>
        <Suffix>index.html</Suffix>
    </IndexDocument>
    <ErrorDocument>
        <Key>errorDocument.html</Key>
    </ErrorDocument>
</WebsiteConfiguration>

Request elements

Name Type Description Required
ErrorDocument container The parent element of the child element key

Parent element: WebsiteConfiguration

No
IndexDocument container The parent element of the child element, suffix

Parent element: WebsiteConfiguration

Yes
Key string The file name used to return Error 404

Parent element: WebsiteConfiguration.ErrorDocument

Conditional: This element is required only when ErrorDocument is set.

Conditional
Suffix string The index file name added when a directory URL is returned. This element cannot be empty or contain a slash (/). For example, if the index file index.html is configured, oss-cn-hangzhou.aliyuncs.com/mybucket/mydir/ contained in an access request is converted into oss-cn-hangzhou.aliyuncs.com/mybucket/index.html by default.

Parent element: WebsiteConfiguration.IndexDocument

Yes.
WebsiteConfiguration container Requested container

Parent element: none

Yes

Detail analysis

  • Static websites are the websites where all web pages are composed of static content, including scripts such as JavaScript executed on the client. OSS does not support content that needs to be processed by the server, such as PHP, JSP, and APS.NET.
  • If you want to use your own domain name to access bucket-based static websites, the CNAME domain name applies. For more information about the configuration method, see Bind custom domain names (CNAME)
  • When you set a bucket to the static website hosting mode, you must specify the index page wherein the error page is optional.
  • When you set a bucket to the static website hosting mode, the specified index page and error page are an object in the bucket.
  • After a bucket is set to a static website hosting mode, OSS returns the index page for anonymous access to the root domain name of the static website, and return Get Bucket results for a signed access to the root domain name of the static website.
  • If you have uploaded the Content-MD5 request header, OSS calculates the body's Content-MD5 and checks if the two are the same. If the two are different, the error code: InvalidDigest is returned.

Examples

Request example:

PUT /? website HTTP/1.1
Host: oss-example.oss-cn-hangzhou.aliyuncs.com
Content-Length: 209
Date: Fri, 04 May 2012 03:21:12 GMT
Authorization: OSS qn6qrrqxo2oawuk53otfjbyc:KU5h8YMUC78M30dXqf3JxrTZHiA=

<? xml version="1.0" encoding="UTF-8"? >
<WebsiteConfiguration>
<IndexDocument>
<Suffix> indexhtml </suffix>
</IndexDocument>
<ErrorDocument>
<Key>error.html</Key>
</ErrorDocument>
</WebsiteConfiguration>

Response example:

HTTP/1.1 200 OK
x-oss-request-id: 534B371674E88A4D8906008B
Date: Fri, 04 May 2012 03:21:12 GMT
Content-Length: 0
Connection: keep-alive
Server: AliyunOSS