文档首页> OBS PHP SDK> API参考> 桶相关接口> 设置桶的Website配置
更新时间:2021-03-18 GMT+08:00
分享

设置桶的Website配置

功能说明

设置桶的Website配置。

方法定义

1. ObsClient->setBucketWebsite(array $parameter)
2. ObsClient->setBucketWebsiteAsync(array $parameter, callable $callback)

请求参数

字段名

类型

约束

说明

Bucket

string

必选

桶名。

RedirectAllRequestsTo

associative array

可选

所有请求重定向规则。

  

HostName

string

必选

重定向请求时使用的站点名。

Protocol

string

可选

重定向请求时使用的协议,支持的值:

  • http(默认)
  • https

ErrorDocument

associative array

可选

错误页面配置。

  

Key

string

可选

指定当4XX错误出现时返回的页面。

IndexDocument

associative array

可选

默认页面配置。

  

Suffix

string

必选

该字段被追加在对文件夹的请求的末尾(例如:配置的是“index.html”,请求的是“samplebucket/images/”,返回的数据将是“samplebucket”桶内名为“images/index.html”的对象的内容)。该字段不能为空或者包含“/”字符。

RoutingRules

indexed array

可选

重定向规则列表。

  

Condition

associative array

可选

重定向规则的匹配条件。

  

HttpErrorCodeReturnedEquals

string

可选

重定向规则生效需要匹配的HTTP错误码。

KeyPrefixEquals

string

可选

重定向规则生效需要匹配的对象名前缀。

Redirect

associative array

必选

重定向请求时的具体信息。

  

Protocol

string

可选

重定向请求时使用的协议,支持的值:

  • http
  • https

HostName

string

可选

重定向请求时使用的站点名。

ReplaceKeyPrefixWith

string

可选

重定向请求时使用的对象名前缀。

ReplaceKeyWith

string

可选

重定向请求时使用的对象名。不可与ReplaceKeyPrefixWith同时存在。

HttpRedirectCode

string

可选

重定向请求时响应中的HTTP状态码。

  • ErrorDocument,IndexDocument和RoutingRules必须配套使用,且与RedirectAllRequestsTo互斥。当设置了这三个字段时,不能设置RedirectAllRequestsTo;反之,当设置了RedirectAllRequestsTo时,不能设置ErrorDocument,IndexDocument和RoutingRules。
  • 当ErrorDocument,IndexDocument和RoutingRules三个字段一起使用时,RoutingRules可为空。
  • ErrorDocument,IndexDocument、RoutingRules与RedirectAllRequestsTo不能全为空。

返回结果

字段名

类型

说明

HttpStatusCode

integer

HTTP状态码。

Reason

string

HTTP文本描述。

RequestId

string

OBS服务端返回的请求ID。

代码样例

try{
       $resp = $obsClient -> setBucketWebsite([
              '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());
}
分享:

    相关文档

    相关产品