web - Set a main page and/or error page for one or more buckets


gsutil web set [-m <main_page_suffix>] [-e <error_page>] gs://<bucket_name>...
gsutil web get gs://<bucket_name>


The Website Configuration feature enables you to configure a Cloud Storage bucket to behave like a static website. This means requests made via a domain-named bucket aliased using a Domain Name System "CNAME" to c.storage.googleapis.com works like any other website. For example, a GET request to the bucket serves the configured "main" page instead of the usual bucket listing and a GET request for a non-existent object serves the configured error page.

For example, suppose your company's domain name is example.com. You could set up a website bucket as follows:

  1. Create a bucket called www.example.com (see the "DOMAIN NAMED BUCKETS" section of "gsutil help naming" for details about creating such buckets).

  2. Create index.html and 404.html files and upload them to the bucket.

  3. Configure the bucket to have website behavior using the command:

    gsutil web set -m index.html -e 404.html gs://www.example.com
  4. Add a DNS CNAME record for www.example.com pointing to c.storage.googleapis.com (ask your DNS administrator for help with this).

Now if you open a browser and navigate to http://www.example.com, it displays the main page instead of the default bucket listing.

Additional notes:

  1. Because the main page is only served when a bucket listing request is made via the CNAME alias, you can continue to use "gsutil ls" to list the bucket and get the normal bucket listing (rather than the main page).
  2. The main_page_suffix applies to each subdirectory of the bucket. For example, with the main_page_suffix configured to be index.html, a GET request for http://www.example.com retrieves http://www.example.com/index.html but shows http://www.example.com as the URL to the requester, and a GET request for http://www.example.com/photos retrieves http://www.example.com/photos/index.html but shows http://www.example.com/photos as the URL to the requester.
  3. There is just one 404.html page. For example, a GET request for http://www.example.com/photos/missing retrieves http://www.example.com/404.html, not http://www.example.com/photos/404.html.
  4. For additional details, see Hosting a static website.

The web command has two sub-commands:


The "gsutil web set" command allows you to configure or disable Website Configuration on your bucket(s). The "set" sub-command has the following options (omit both options to unset configuration):

Set Options

-m <index.html>
 Specifies the object name to serve when a bucket listing is requested via the CNAME alias to c.storage.googleapis.com.
-e <404.html> Specifies the error page to serve when a request is made for a non-existent object via the CNAME alias to c.storage.googleapis.com.


The "gsutil web get" command retrieves the web semantics configuration for a bucket and displays a JSON representation of the configuration.

In Cloud Storage, this would look like the following:

  "notFoundPage": "404.html",
  "mainPageSuffix": "index.html"