You need to enable JavaScript to run this app.
文档中心
对象存储

对象存储

复制全文
下载 pdf
静态网站托管
PutBucketWebsite
复制全文
下载 pdf
PutBucketWebsite
功能描述​
您可以通过 PutBucketWebsite 接口,将 Bucket 设置为静态网站托管模式,并设置跳转规则。该模式支持以下功能:​
  • 重定向所有请求到另外一个站点。​
  • 设置特定规则重定向特定请求。​
注意事项​
  • 调用此接口您必须为桶所有者,或被授权当前桶的 PutBucketWebsite 权限。​
  • 最多只能设置 50 条重定向规则。​
  • 您必须设置自定义域名后,静态网站托管模式才能生效。​
请求消息样式​
​
PUT /?website HTTP/1.1​
Host: bucketname.tos-cn-beijing.volces.com​
Date: Fri, 30 Jul 2021 08:05:36 +0000​
Authorization: authorization string​
Content-Length: 120​
​
{​
"RedirectAllRequestsTo": {​
"HostName": "example.com",​
"Protocol": "https"​
},​
"IndexDocument": {​
"Suffix": "index.html",​
"ForbiddenSubDir": "false"​
},​
"ErrorDocument": {​
"Key": "error.html"​
},​
"RoutingRules": [​
{​
"Condition": {​
"HttpErrorCodeReturnedEquals": 404,​
"KeyPrefixEquals": "red/"​
},​
"Redirect": {​
"HostName": "example.com",​
"HttpRedirectCode": 301,​
"Protocol": "http",​
"ReplaceKeyPrefixWith": "redirect/",​
"ReplaceKeyWith": "redirect.html"​
}​
}​
]​
}​
​
请求参数和消息头​
该请求使用的公共请求消息头,请参见公共参数。​
​
名称​
位置​
参数类型​
是否必选​
示例值​
说明​
website​
Query​
String​
是​
-​
代表 PutBucketWebsite 请求的特殊标识。​
​
请求元素​
重定向所有请求​
​
名称​
参数类型​
是否必选​
示例值​
说明​
RedirectAllRequestsTo​
Object​
否​
-​
重定向所有请求,设置后不能再设置其他重定向规则。​
HostName​
String​
若使用RedirectAllRequestsTo,则必选​
example.com​
重定向的站点名。​
父节点:RedirectAllRequestsTo​
Protocol​
String​
否​
http​
重定向请求时使用的协议,支持 http 和 https 协议。默认使用 http 协议。​
父节点:RedirectAllRequestsTo​
​
重定向规则​
  • 默认主页 IndexDocument​
​
名称​
参数类型​
是否必选​
示例值​
说明​
IndexDocument​
Object​
否​
-​
设置默认主页。​
Suffix​
String​
若使用 IndexDocument,则必选​
index.html​
访问目录请求时(结尾为 / ),返回该目录下的 Suffix 对象。例如 Suffix 设置为 index.html 后,访问 docment/ 时,则返回 document/index.html。​
父节点:IndexDocument​
ForbiddenSubDir​
Bool​
否​
false​
是否支持转到子目录的默认主页,取值说明如下:​
  • false(默认):不支持跳转到子目录的默认首页。​
  • true:支持跳转到子目录的默认首页。​
父节点:IndexDocument​
​
  • 报错页面 ErrorDocument​
​
名称​
参数类型​
是否必选​
示例值​
说明​
ErrorDocument​
Object​
否​
-​
设置报错页面。​
Key​
String​
若使用 ErrorDocument,则必选​
error.html​
当出现 4xx 错误时,则返回该页面。​
父节点:ErrorDocument​
​
  • 重定向规则 RoutingRules​
​
名称​
参数类型​
是否必选​
示例值​
说明​
RoutingRules​
Array​
否​
-​
设置重定向规则。​
Condition​
Object​
若使用 RoutingRules, 则必选​
-​
设置重定向规则的匹配条件。只有当设置的条件全部匹配后,重定向规则才能生效。​
父节点:RoutingRules​
HttpErrorCodeReturnedEquals​
Integer​
否​
404​
设置重定向生效时的 HTTP 错误码。例如设置 HttpErrorCodeReturnedEquals 为 404,那么当访问指定对象不存在时,规则生效。​
如果设置了 KeyPrefixEquals,则两个条件都匹配时,重定向规则才能生效。​
父节点:Condition​
KeyPrefixEquals​
String​
否​
red/​
设置重定向规则生效时的对象名前缀。​
如果设置了HttpErrorCodeReturnedEquals,则两个条件都匹配时,重定向规则才能生效。​
父节点:Condition​
Redirect​
Object​
若使用 RoutingRules, 则必选​
-​
设置重定向规则。​
父节点:RoutingRules​
HostName​
String​
否​
example.com​
设置重定向的站点名。​
父节点:Redirect​
HttpRedirectCode​
Integer​
否​
301​
跳转时返回的状态码,只能设置 3XX 的错误码,不能设置 300, 默认为 301。​
父节点:Redirect​
Protocol​
String​
否​
http​
重定向请求时使用的协议,支持 http 和 https 协议。默认使用 http 协议。​
父节点:Redirect​
ReplaceKeyPrefixWith​
String​
否​
redirect/​
重定向时使用的对象名前缀。​
不能与 ReplaceKeyWith 同时设置。​
父节点:Redirect​
ReplaceKeyWith​
String​
否​
redirect.html​
重定向时使用的对象名。​
不能与 ReplaceKeyPrefixWith 同时设置。​
父节点:Redirect​
​
响应消息头​
该请求返回的公共响应消息头,请参见公共参数。​
响应元素​
该请求响应中无消息元素。​
请求示例 1​
​
PUT /?website HTTP/1.1​
Host: bucketname.tos-cn-beijing.volces.com​
Date: Fri, 30 Jul 2021 08:05:36 +0000​
Authorization: authorization string​
Content-Length: 76​
​
{​
"RedirectAllRequestsTo": {​
"HostName": "example.com"​
}​
}​
​
响应示例 1​
​
HTTP/1.1 200 OK​
x-tos-id-2: f91b0c03a01300c1-a444ed0 ​
x-tos-request-id: f91b0c03a01300c1-a444ed0 ​
Date: Fri, 30 Jul 2021 06:45:39 GMT​
server: TosServer​
​
请求示例 2​
​
PUT /?website HTTP/1.1​
Host: bucketname.tos-cn-beijing.volces.com​
Date: Fri, 30 Jul 2021 08:05:36 +0000​
Authorization: authorization string​
Content-Length: 122​
​
{​
"IndexDocument": {​
"Suffix": "index.html"​
},​
"ErrorDocument": {​
"Key": "error.html"​
}​
}​
​
响应示例 2​
​
HTTP/1.1 200 OK​
x-tos-id-2: f91b0c03a01300c1-a444ed0 ​
x-tos-request-id: f91b0c03a01300c1-a444ed0 ​
Date: Fri, 30 Jul 2021 06:45:39 GMT​
server: TosServer​
​
​
最近更新时间:2026.02.10 10:31:11
这个页面对您有帮助吗?
有用
有用
无用
无用