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 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 Parent: 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 Parent: WebsiteConfiguration |
Yes |
HostName |
Name of the host where requests will be redirected Type: string Parent: RedirectAllRequestsTo |
Yes |
Protocol |
The HTTP or HTTPS protocol used in redirecting requests. The default protocol is HTTP. Type: string Parent: RedirectAllRequestsTo |
No |
Element |
Description |
Mandatory |
---|---|---|
WebsiteConfiguration |
Root element for the website configuration Type: container Parent: none |
Yes |
IndexDocument |
Suff element Type: container Parent: 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 Parent: IndexDocument |
Yes |
ErrorDocument |
Key element Type: container Parent: 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 Parent: ErrorDocument Condition: Required when ErrorDocument is specified. |
No |
RoutingRules |
Routing element Type: container Parent: 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 Parent: 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 Parent: RoutingRule |
No |
KeyPrefixEquals |
Object key name prefix when the redirection is applied. Example:
Type: string Parent: 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 Parent: 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 Parent: RoutingRule |
Yes |
Protocol |
Protocol used in the redirection request Type: string Parent: 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 Parent: Redirect Condition: Not required if one of the siblings is present. |
No |
ReplaceKeyPrefixWith |
The object name prefix used in the redirection request. OBS replaces the value of KeyPrefixEquals with the value you specified here for ReplaceKeyPrefixWith. Example: To redirect all requests for docs (objects in the docs directory) to documents (objects in the documents directory), set KeyPrefixEquals to docs under Condition and ReplaceKeyPrefixWith to documents under Redirect. This way, requests for object docs/a.html will be redirected to documents/a.html. Type: string Parent: Redirect Condition: Not required if one of the siblings is present. Can be present only if ReplaceKeyWith is not provided. |
No |
ReplaceKeyWith |
The object name used in the redirection request. OBS replaces the entire object name in the request with the value you specified here for ReplaceKeyWith. Example: To redirect requests for all objects in the docs directory to documents/error.html, set KeyPrefixEquals to docs under Condition and ReplaceKeyWith to documents/error.html under Redirect. This way, requests for both objects docs/a.html and docs/b.html will be redirected to documents/error.html. Type: string Parent: 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 Parent: 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 elements.
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 |