您可以通过 PutBucketWebsite 接口,将 Bucket 设置为静态网站托管模式,并设置跳转规则。该模式支持以下功能:
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 | 重定向的站点名。 |
Protocol | String | 否 | http | 重定向请求时使用的协议,支持 http 和 https 协议。默认使用 http 协议。 |
名称 | 参数类型 | 是否必选 | 示例值 | 说明 |
---|---|---|---|---|
IndexDocument | Object | 否 | - | 设置默认主页。 |
Suffix | String | 若使用 IndexDocument,则必选 | index.html | 访问目录请求时(结尾为 |
ForbiddenSubDir | Bool | 否 | false | 是否支持转到子目录的默认主页,取值说明如下:
父节点:IndexDocument |
名称 | 参数类型 | 是否必选 | 示例值 | 说明 |
---|---|---|---|---|
ErrorDocument | Object | 否 | - | 设置报错页面。 |
Key | String | 若使用 ErrorDocument,则必选 | error.html | 当出现 4xx 错误时,则返回该页面。 |
名称 | 参数类型 | 是否必选 | 示例值 | 说明 |
---|---|---|---|---|
RoutingRules | Array | 否 | - | 设置重定向规则。 |
Condition | Object | 若使用 RoutingRules, 则必选 | - | 设置重定向规则的匹配条件。只有当设置的条件全部匹配后,重定向规则才能生效。 |
HttpErrorCodeReturnedEquals | Integer | 否 | 404 | 设置重定向生效时的 HTTP 错误码。例如设置 |
KeyPrefixEquals | String | 否 | red/ | 设置重定向规则生效时的对象名前缀。 |
Redirect | Object | 若使用 RoutingRules, 则必选 | - | 设置重定向规则。 |
HostName | String | 否 | example.com | 设置重定向的站点名。 |
HttpRedirectCode | Integer | 否 | 301 | 跳转时返回的状态码,只能设置 3XX 的错误码,不能设置 300, 默认为 301。 |
Protocol | String | 否 | http | 重定向请求时使用的协议,支持 http 和 https 协议。默认使用 http 协议。 |
ReplaceKeyPrefixWith | String | 否 | redirect/ | 重定向时使用的对象名前缀。 |
ReplaceKeyWith | String | 否 | redirect.html | 重定向时使用的对象名。 |
该请求返回的公共响应消息头,请参见公共参数。
该请求响应中无消息元素。
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" } }
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
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" } }
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