Set bucket website

At the time they are created, buckets do not have any website configuration set. To set or modify the website configuration for an existing bucket you make a PUT request that is scoped to the bucket and you use the websiteConfig query string parameter. You must include an XML document in the request body that contains the website configuration that you want to apply.

You must have FULL_CONTROL permission to set or modify the website configuration for an existing bucket. Also, you must be authenticated to use the PUT Bucket method.

For more information on using a bucket to host a static website, including other options for setting your website configuration, see Hosting a Static Website.

Query string parameters

Parameter Description Required
websiteConfig You use this to change the website configuration on an existing bucket. You must provide the WebsiteConfiguration document in the request body. No

See signed URL query string parameters for information on the parameters you include when creating and using signed URLs.

Request headers

See common request headers.

Request body elements

The following request body elements are applicable only if you use the websiteConfig query string parameter to specify a website configuration for an existing bucket.

Element Description
WebsiteConfiguration Container for website configuration.
MainPageSuffix An object name suffix to simulate directory index behavior. Must be a valid object name. Optional.
NotFoundPage Name of the object to return with 404 responses. Must be a valid object name. Optional.

Request syntax

PUT /?websiteConfig HTTP/1.1
Host: BUCKET_NAME.storage.googleapis.com
Date: DATE
Content-Length: REQUEST_BODY_LENGTH
Content-Type: MIME_TYPE_OF_THE_BODY
Authorization: AUTHENTICATION_STRING

XML_DOCUMENT_DEFINING_WEBSITE_CONFIG

Response headers

The request can return a variety of response headers depending on the request headers you use.

Response body elements

The response does not include an XML document in the response body.

Example

Request

PUT /?websiteConfig HTTP/1.1
Host: storage.googleapis.com
Content-Length: 156
Authorization: Bearer ya29.AHES6ZRVmB7fkLtd1XTmq6mo0S1wqZZi3-Lh_s-6Uw7p8vtgSwg

<WebsiteConfiguration>
  <MainPageSuffix>index.html</MainPageSuffix>
  <NotFoundPage>404.html</NotFoundPage>
</WebsiteConfiguration>

Response

HTTP/1.1 200 OK
Date: Thu, 12 Mar 2012 03:38:42 GMT
Expires: Mon, 01 Jan 1990 00:00:00 GMT
Cache-Control: no-cache, no-store, must-revalidate
Content-Length: 0
Content-Type: text/html