OBS allows you to store static web page resources such as HTML web pages, flash files, videos, and audios in a bucket. When a client accesses these resources from the website endpoint of the bucket, the browser can directly resolve and present the resources to the client. This operation is applicable to:
You can perform this operation to create or update the website configuration of a bucket.
To perform this operation, you must have the PutBucketWebsite permission. By default, only the bucket owner can perform this operation. The bucket owner can grant the permission to other users by configuring the bucket policy or user policy.
Avoid using periods (.) in the destination bucket name. Otherwise, failures in client authentication certificate may occur when users use HTTPS for access.
The maximum size of a network configuration request for a bucket is 10 KB.
1 2 3 4 5 6 7 8 9 10 | PUT /?website HTTP/1.1 Host: bucketname.obs.region.example.com Content-Length: length Date: date Authorization: authorization <WebsiteConfiguration> <RedirectAllRequestsTo> <HostName>hostName</HostName> </RedirectAllRequestsTo> </WebsiteConfiguration> |
This request contains no message parameters.
This request uses common headers. For details, see Table 3.
This request contains elements to specify the website configuration in XML format.
Element |
Description |
Mandatory |
---|---|---|
WebsiteConfiguration |
Root node configured on the website Type: container Ancestor: none |
Yes |
RedirectAllRequestsTo |
Describes the redirection behavior for every request to this bucket's website endpoint. If this element is present, no other siblings are allowed. Type: container Ancestor: WebsiteConfiguration |
Yes |
HostName |
Name of the host where requests will be redirected Type: string Ancestor: RedirectAllRequestsTo |
Yes |
Protocol |
The HTTP or HTTPS protocol used in redirecting requests. The default protocol is HTTP. Type: string Ancestor: RedirectAllRequestsTo |
No |
Element |
Description |
Mandatory |
---|---|---|
WebsiteConfiguration |
Root element for the website configuration Type: container Ancestor: none |
Yes |
IndexDocument |
Suff element Type: container Ancestor: WebsiteConfiguration |
Yes |
Suffix |
Suffix that is appended to a request initiated for a directory on the website endpoint. For example, if the suffix is index.html and you request for samplebucket/images/, the data that is returned will be for the object with the key name images/index.html in the samplebucket bucket. Suffix cannot be empty or contain slashes (/). Type: string Ancestor: IndexDocument |
Yes |
ErrorDocument |
Key element Type: container Ancestor: WebsiteConfiguration |
No |
Key |
Object key that is used when a 4XX error occurs. This element identifies the page that is returned when a 4XX error occurs. Type: string Ancestor: ErrorDocument Condition: Required when ErrorDocument is specified. |
No |
RoutingRules |
Routing element Type: container Ancestor: WebsiteConfiguration |
No |
RoutingRule |
Element of a redirection rule. A redirection rule contains a Condition and a Redirect. When the Condition is matched, Redirect takes effect. Type: container Ancestor: RoutingRules At least the RoutingRule element is required. |
Yes |
Condition |
Element for describing a condition that must be met for the specified redirection to apply. Type: container Ancestor: RoutingRule |
No |
KeyPrefixEquals |
Object key name prefix when the redirection is applied. Example:
Type: string Ancestor: Condition Condition: Required when the ancestor element Condition is specified and sibling HttpErrorCodeReturnedEquals is not specified. If two conditions are specified, both conditions must be true for the Redirect to be applied. |
No |
HttpErrorCodeReturnedEquals |
HTTP error code returned after the Redirect has taken effect. The specified Redirect is applied only when the error code returned equals this value. Example:
Type: string Ancestor: Condition Condition: Required when ancestor element Condition is specified and sibling KeyPrefixEquals is not specified. If multiple conditions are specified, the Redirect takes effect only after all conditions are met. |
No |
Redirect |
Element for redirection information. You can redirect requests to another host, to another web page, or with another protocol. You can specify an error code to be returned after an error. Type: container Ancestor: RoutingRule |
Yes |
Protocol |
Protocol used in the redirection request Type: string Ancestor: Redirect Value options: http, https Condition: Not required if one of the siblings is present. |
No |
HostName |
Host name used in the redirection request. Type: string Ancestor: Redirect Condition: Not required if one of the siblings is present. |
No |
ReplaceKeyPrefixWith |
Object key prefix used in the redirection request. Example:
Type: string Ancestor: Redirect Condition: Not required if one of the siblings is present. Can be present only if ReplaceKeyWith is not provided. |
No |
ReplaceKeyWith |
Object key used in the redirection request. For example, redirect requests to error.html. Type: string Ancestor: Redirect Condition: Not required if one of the siblings is present. Can be present only if ReplaceKeyPrefixWith is not provided. |
No |
HttpRedirectCode |
HTTP status code returned after the redirection request Type: string Ancestor: Redirect Condition: Not required if one of the siblings is present. |
No |
1 2 3 | HTTP/1.1 status_code Date: date Content-Length: length |
The response to the request uses common headers. For details, see Table 1.
This response contains no element.
No special error responses are returned. For details about error responses, see Table 2.
1 2 3 4 5 6 7 8 9 10 11 12 13 | PUT /?website HTTP/1.1 User-Agent: curl/7.29.0 Host: examplebucket.obs.region.example.com Accept: */* Date: WED, 01 Jul 2015 03:40:29 GMT Authorization: OBS H4IPJX0TQTHTHEBQQCEC:pUK7Yp0yebnq4P6gqzVjoS7whoM= Content-Length: 194 <WebsiteConfiguration xmlns="http://obs.example.com/doc/2015-06-30/"> <RedirectAllRequestsTo> <HostName>www.example.com</HostName> </RedirectAllRequestsTo> </WebsiteConfiguration> |
1 2 3 4 5 6 | HTTP/1.1 200 OK Server: OBS x-obs-request-id: BF2600000164360D144670B9D02AABC6 x-obs-id-2: 32AAAQAAEAABSAAgAAEAABAAAQAAEAABCSItqMZ/AoFUX97l1xx8s67V3cCQtXWk Date: WED, 01 Jul 2015 03:40:29 GMT Content-Length: 0 |