Set Bucket Website

By default, 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 website query string parameter. You must include an XML document in the request body that contains the website configuration that you want to apply. You cannot set a website configuration while creating a new bucket.

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

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>.storage.googleapis.com
Date: <date and time of the request>
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

Monitor your resources on the go

Get the Google Cloud Console app to help you manage your projects.

Send feedback about...

Cloud Storage Documentation