• Object Storage Service

obs
  1. Help Center
  2. Object Storage Service
  3. API Reference (OBS)
  4. Operations on Buckets
  5. PUT Bucket website
  6. Requests

Requests

Syntax

 PUT /?website HTTP/1.1 
 User-Agent: agent
 Host: bucketname.obs.example.com
 Accept: */* 
 Content-Length: length 
 Date: date 
 Authorization: authorization 
 Expect: expect

 <WebsiteConfiguration> 
   <RedirectAllRequestsTo> 
     <HostName>hostName</HostName> 
   </RedirectAllRequestsTo> 
 </WebsiteConfiguration>

Request Parameters

This request involves no parameters.

Request Headers

This request uses common headers. For details about common request headers, see section Common Request Headers.

Request Elements

This request contains elements to specify the website configuration in the XML format. The elements differ for situations where users want to redirect all requests to a website endpoint and for when users want to add routing rules that redirect specific requests.

  • To redirect all websites requests sent to the bucket's website endpoint, add the elements as described in Table 1.
Table 1 Elements for redirecting all website requests

Element

Description

Remarks

WebsiteConfiguration

Indicates the root element for the website configuration.

Type: Container

Ancestor: None

Mandatory

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

Mandatory

HostName

Indicates the name of the host where requests will be redirected.

Type: String

Ancestor: RedirectAllRequestsTo

Mandatory

Protocol

Indicates the protocol (HTTP and HTTPS) used in redirecting requests. The default protocol is HTTP.

Type: String

Ancestor: RedirectAllRequestsTo

Optional

  • To add routing rules that describe conditions for redirecting requests, add the elements as described in Table 2.
Table 2 Elements for adding rules that redirect requests

Element

Description

Remarks

WebsiteConfiguration

Indicates the root element for the website configuration.

Type: Container

Ancestor: None

Mandatory

IndexDocument

Indicates the container for the Suffix element.

Type: Container

Ancestor: WebsiteConfiguration

Mandatory

Suffix

Indicates a 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. The suffix cannot be empty or contain slashes (/).

Type: String

Ancestor: IndexDocument

Mandatory

ErrorDocument

Indicates the container for the Key element.

Type: Container

Ancestor: WebsiteConfiguration

Optional

key

Indicates the 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.

Optional

RoutingRules

Indicates the container for the RoutingRule element.

Type: Container

Ancestor: WebsiteConfiguration

Optional

RoutingRule

Indicates the container for a routing rule that identifies a condition and a redirect applicable when the condition is met.

Type: Container

Ancestor: RoutingRules

Condition: In a RoutingRules container, there must be at least one RoutingRule element.

Mandatory

Condition

Indicates the container for describing a condition that must be met for the specified redirect to apply.

Type: Container

Ancestor: RoutingRule

Optional

KeyPrefixEquals

Indicates the object key name prefix when the redirection is applied.

For example:

  • To redirect the request for object ExamplePage.html, the key prefix is set to ExamplePage.html.

Type: String

Ancestor: Condition

Condition: Required when the parent element HttpErrorCodeReturnedEquals is not specified. If two conditions are specified, both conditions must be true for the redirection to be applied.

Optional

HttpErrorCodeReturnedEquals

Indicates the HTTP error code returned when the redirection is applied. The specified redirect is applied only when the error code returned equals to this value.

For example:

  • If you want to redirect to NotFound.html when HTTP error code 404 is returned, set HttpErrorCodeReturnedEquals to 404 in Condition and ReplaceKeyWith to NotFound.html in Redirect.

Type: String

Ancestor: Condition

Condition: Required when parent element Condition is specified and sibling KeyPrefixEquals is not specified. If multiple conditions are specified, the redirection takes effect only after all conditions are met.

Optional

Redirect

Indicates the container for redirect 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

Mandatory

Protocol

Indicates the protocol used in the redirection request.

Type: String

Ancestor: Redirect

Valid Values: http, https

Condition: Not required if one of the siblings is present.

Optional

HostName

Indicates the host name used in the redirection request.

Type: String

Ancestor: Redirect

Condition: Not required if one of the siblings is present.

Optional

ReplaceKeyPrefixWith

Indicates the object key prefix used in the redirection request.

For example:

  • To redirect all requests for (objects under) docs to (objects under) documents, set KeyPrefixEquals to docs in Condition and ReplaceKeyPrefixWith to documents in Redirect.

Type: String

Ancestor: Redirect

Condition: Not required if one of the siblings is present. Can be present only if ReplaceKeyWith is not provided.

Optional

ReplaceKeyWith

Indicates the 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 ReplaceKeyPrefixWithis not provided.

Optional

HttpRedirectCode

Indicates the HTTP status code returned after the redirection request.

Type: String

Ancestor: Redirect

Condition: Not required if one of the siblings is present.

Optional