web - Set a website configuration for a bucket
Synopsis
gsutil web set [-m <main_page_suffix>] [-e <error_page>] gs://<bucket_name>...
gsutil web get gs://<bucket_name>
Description
Cloud Storage allows you to configure a bucket to behave like a static
website when the bucket is accessed through a custom domain.
For example, if you set a main_page_suffix
, a subsequent GET bucket
request through a custom domain serves the specified "main" page instead of
performing the usual bucket listing. Similarly, if you set an error_page
,
a subsequent GET object request through a custom domain for a non-existent
object serves the specified error page instead of the standard Cloud Storage
error.
Requests to a bucket through other endpoints are unaffected by the bucket's website configuration.
See Static website examples and tips for additional examples and information.
Notes:
Because the main page is only served when a bucket listing request is made via a custom domain endpoint, you can continue to use
gsutil ls
as you normally would for bucket listing.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
retrieveshttp://www.example.com/index.html
but showshttp://www.example.com
as the URL to the requester, and a GET request forhttp://www.example.com/photos
retrieveshttp://www.example.com/photos/index.html
but showshttp://www.example.com/photos
as the URL to the requester.There is just one 404.html page. For example, a GET request for
http://www.example.com/photos/missing
retrieveshttp://www.example.com/404.html
, nothttp://www.example.com/photos/404.html
.
The web command has two sub-commands:
Set
The gsutil web set
command allows you to configure or disable the website
configuration on your buckets. The set
sub-command has the following
options (omit both options to unset the configuration):
Set Options
- -m <index.html>
Specifies the object name to serve when a bucket listing is requested via a custom domain.
- -e <404.html>
Specifies the error page to serve when a request is made for a non-existent object via a custom domain
Get
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"
}