本文档提供关于静态网站的 API 概览以及 SDK 示例代码。
设置静态网站
功能说明
PUT Bucket website 用于为存储桶配置静态网站。
方法原型
public Guzzle\Service\Resource\Model PutBucketWebsite(array $args = array());
请求示例
<?php
require dirname(__FILE__) . '/../vendor/autoload.php';
$secretId = "SECRETID";
$secretKey = "SECRETKEY";
$region = "ap-beijing";
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'schema' => 'https',
'credentials'=> array(
'secretId' => $secretId ,
'secretKey' => $secretKey)));
try {
$result = $cosClient->putBucketWebsite(array(
'Bucket' => 'examplebucket-1250000000',
'IndexDocument' => array(
'Suffix' => 'index.html',
),
'RedirectAllRequestsTo' => array(
'Protocol' => 'https',
),
'ErrorDocument' => array(
'Key' => 'Error.html',
),
'RoutingRules' => array(
array(
'Condition' => array(
'HttpErrorCodeReturnedEquals' => '405',
),
'Redirect' => array(
'Protocol' => 'https',
'ReplaceKeyWith' => '404.html',
),
),
),
));
print_r($result);
} catch (\Exception $e) {
echo "$e\n";
}
参数说明
参数名称 |
父节点 |
描述 |
类型 |
是否必选 |
Bucket |
无 |
设置静态网站的存储桶,格式为 BucketName-APPID ,详情请参见 命名规范 |
String |
是 |
IndexDocument |
无 |
索引文档 |
Array |
是 |
Suffix |
IndexDocument |
指定索引文档 |
String |
是 |
ErrorDocument |
无 |
错误文档 |
Array |
否 |
Key |
ErrorDocument |
指定通用错误返回 |
String |
否 |
RedirectAllRequestsTo |
无 |
重定向所有请求 |
Array |
否 |
Protocol |
RedirectAllRequestsTo |
指定全站重定向的协议,只能设置为 https |
String |
否 |
RoutingRules |
无 |
设置重定向规则,最多设置100条 RoutingRule |
Array |
否 |
RoutingRule |
RoutingRules |
设置单条重定向规则,包括前缀匹配重定向和错误码重定向 |
Array |
否 |
Condition |
RoutingRule |
指定重定向发生的条件,前缀匹配重定向和错误码重定向只能指定一个 |
Array |
否 |
HttpErrorCodeReturnedEquals |
Condition |
指定重定向错误码,只支持配置4XX返回码,优先级高于 ErrorDocument |
Interger |
否 |
KeyPrefixEquals |
Condition |
指定前缀重定向的路径,替换指定的 folder/ |
String |
否 |
Redirect |
RoutingRule |
指定满足重定向 conditon 时重定向的具体替换规则 |
Array |
否 |
ReplaceKeyWith |
Redirect |
替换整个 Key 为指定的内容 |
String |
否 |
ReplaceKeyPrefixWith |
Redirect |
替换匹配到的前缀为指定的内容,Conditon 为 KeyPrefixEquals 才可设置 |
String |
否 |
查询静态网站配置
功能说明
GET Bucket website 用于查询与存储桶关联的静态网站配置信息。
方法原型
public Guzzle\Service\Resource\Model GetBucketWebsite(array $args = array());
请求示例
<?php
require dirname(__FILE__) . '/../vendor/autoload.php';
$secretId = "SECRETID";
$secretKey = "SECRETKEY";
$region = "ap-beijing";
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'schema' => 'https',
'credentials'=> array(
'secretId' => $secretId ,
'secretKey' => $secretKey)));
try {
$result = $cosClient->getBucketWebsite(array(
'Bucket' => 'examplebucket-1250000000',
));
print_r($result);
} catch (\Exception $e) {
echo "$e\n";
}
参数说明
参数名称 |
描述 |
类型 |
bucket |
查询静态网站配置的存储桶,格式为 BucketName-APPID,详情请参见 命名规范 |
String |
返回结果示例
GuzzleHttp\Command\Result Object
(
[RedirectAllRequestsTo] => Array
(
[Protocol] => https
)
[IndexDocument] => Array
(
[Suffix] => index.html
)
[ErrorDocument] => Array
(
[Key] => Error.html
)
[RoutingRules] => Array
(
[0] => Array
(
[Condition] => Array
(
[HttpErrorCodeReturnedEquals] => 405
)
[Redirect] => Array
(
[Protocol] => https
[ReplaceKeyWith] => 404.html
)
)
)
[RequestId] => NWRmMzQ3YjlfMTlhYTk0MGFfNzMzYl84YWIy****
)
返回结果说明
参数名称 |
描述 |
类型 |
Bucket |
存储桶名称格式为 BucketName-APPID ,详情请参见 命名规范 |
String |
IndexDocument |
索引文档 |
Array |
Suffix |
指定索引文档 |
String |
ErrorDocument |
错误文档 |
Array |
Key |
指定通用错误返回 |
String |
RedirectAllRequestsTo |
重定向所有请求 |
Array |
Protocol |
指定全站重定向的协议,只能设置为 https |
String |
RoutingRules |
设置重定向规则,最多设置100条 RoutingRule |
Array |
RoutingRule |
设置单条重定向规则,包括前缀匹配重定向和错误码重定向 |
Array |
Condition |
指定重定向发生的条件,前缀匹配重定向和错误码重定向只能指定一个 |
Array |
HttpErrorCodeReturnedEquals |
指定重定向错误码,只支持配置4XX返回码,优先级高于 ErrorDocument |
Interger |
KeyPrefixEquals |
指定前缀重定向的路径,替换指定的 folder/ |
String |
Redirect |
指定满足重定向 conditon 时重定向的具体替换规则 |
Array |
ReplaceKeyWith |
替换整个 Key 为指定的内容 |
String |
ReplaceKeyPrefixWith |
替换匹配到的前缀为指定的内容,Conditon 为 KeyPrefixEquals 才可设置 |
String |
删除静态网站配置
功能说明
DELETE Bucket website 用于删除存储桶中的静态网站配置。
方法原型
public Guzzle\Service\Resource\Model DeleteBucketWebsite(array $args = array());
请求示例
<?php
require dirname(__FILE__) . '/../vendor/autoload.php';
$secretId = "SECRETID";
$secretKey = "SECRETKEY";
$region = "ap-beijing";
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'schema' => 'https',
'credentials'=> array(
'secretId' => $secretId ,
'secretKey' => $secretKey)));
try {
$result = $cosClient->deleteBucketWebsite(array(
'Bucket' => 'examplebucket-1250000000',
));
print_r($result);
} catch (\Exception $e) {
echo "$e\n";
}
参数说明
参数名称 |
描述 |
类型 |
bucket |
被删除静态网站配置的存储桶,格式为 BucketName-APPID ,详情请参见 命名规范 |
String |