• Object Storage Service

obs
  1. Help Center
  2. Object Storage Service
  3. API Reference (PHP SDK)
  4. Bucket-Related APIs
  5. PUT Bucket website

PUT Bucket website

API Description

You can use this API to set website hosting for a bucket.

Method Definition

1. ObsClient->setBucketWebsiteConfiguration(array $parameter)
2. ObsClient->setBucketWebsiteConfigurationAsync(array $parameter, callable $callback)

Request Parameter

Field

Type

Optional or Mandatory

Description

Bucket

string

Mandatory

Bucket name

RedirectAllRequestsTo

associative array

Optional

Redirection rule of all requests

  

HostName

string

Mandatory

Host name used for redirection

Protocol

string

Optional

Protocol used for redirection. Possible values are:

  • http (default)
  • https

ErrorDocument

associative array

Optional

Error page settings

  

Key

string

Optional

Page that is returned when a 4XX error occurs

IndexDocument

associative array

Optional

Default page settings

  

Suffix

string

Mandatory

Suffix that is appended to a request initiated for a folder. For example, if the suffix is index.html and you request for samplebucket/images/, the returned data will be the object named images/index.html in the samplebucket bucket. The suffix can neither be null nor contain slashes (/).

RoutingRules

indexed array

Optional

Redirection rule list

  

Condition

associative array

Optional

Matching condition of a redirection rule

  

HttpErrorCodeReturnedEquals

string

Optional

HTTP error code to be matched when a redirection rule takes effect

KeyPrefixEquals

string

Optional

Object name prefix to be matched when a redirection rule takes effect

Redirect

associative array

Mandatory

Details about a redirection request

  

Protocol

string

Optional

Protocol used for redirection. Possible values are:

  • http
  • https

HostName

string

Optional

Host name used for redirection

ReplaceKeyPrefixWith

string

Optional

Object name prefix used in the redirection request

ReplaceKeyWith

string

Optional

Object name used in the redirection request. This parameter cannot be used together with ReplaceKeyPrefixWith.

HttpRedirectCode

string

Optional

HTTP status code in the response to the redirection request

NOTE:
  • ErrorDocumentIndexDocument, and RoutingRules must be used together and they cannot be used with RedirectAllRequestsTo.
  • When ErrorDocumentIndexDocument, and RoutingRules are used together, RoutingRules can be null.
  • You must set either these three fields or RedirectAllRequestsTo.

Returned Result

Field

Type

Description

HttpStatusCode

integer

HTTP status code

Reason

string

Reason description

RequestId

string

Request ID returned by the OBS server

Sample Code

try{
       $resp = $obsClient -> setBucketWebsiteConfiguration([
              'Bucket' => 'bucketname',
//            'RedirectAllRequestsTo' => ['HostName' => 'www.example.com', 'Protocol' => 'https'],
              'IndexDocument' => ['Suffix' => 'index.html'],
              'ErrorDocument' => ['Key' => 'error.html'],
              'RoutingRules' => [
                     ['Condition' => ['HttpErrorCodeReturnedEquals' => 404, 'KeyPrefixEquals' => 'prefix'], 'Redirect' => ['Protocol' => 'http', 'ReplaceKeyWith' => 'key']],
                     ['Condition' => ['HttpErrorCodeReturnedEquals' => 404, 'KeyPrefixEquals' => 'prefix'], 'Redirect' => ['Protocol' => 'http', 'ReplaceKeyWith' => 'key']]
              ]
       ]);
       printf("RequestId:%s\n", $resp['RequestId']);
}catch (Obs\Common\ObsException $obsException){
       printf("ExceptionCode:%s\n", $obsException->getExceptionCode());
       printf("ExceptionMessage:%s\n", $obsException->getExceptionMessage());
}