Enables static website hosting and configures redirection rules for a bucket.
Usage notes
By default, an Alibaba Cloud account has the permissions to enable static website hosting and configure redirection rules for a bucket. To enable static website hosting and configure redirection rules for a bucket by using a RAM user or Security Token Service (STS), you must have the
oss:PutBucketWebsite
permission. For more information, see Attach a custom policy to a RAM user.Before you enable static website hosting, make sure that you familiarize yourself with this feature. For more information, see Overview of static website hosting.
Command syntax
ossutil api put-bucket-website --bucket value --website-configuration value [flags]
Parameter | Type | Description |
--bucket | string | The name of the bucket. |
--website-configuration | string | The root node of the website. |
The put-bucket-website command corresponds to the PutBucketWebsite operation. For more information about the parameters in the PutBucketWebsite operation, see PutBucketWebsite.
--website-configuration
The --website-configuration option supports both the XML and JSON formats. If the value of the option contains the file:// prefix, ossutil reads configurations from a configuration file
XML format:
<WebsiteConfiguration> <IndexDocument> <Suffix>string</Suffix> <SupportSubDir>boolean</SupportSubDir> <Type>string</Type> </IndexDocument> <ErrorDocument> <Key>string</Key> <HttpStatus>string</HttpStatus> </ErrorDocument> <RoutingRules> <RoutingRule> <RuleNumber>integer</RuleNumber> <Condition> <KeyPrefixEquals>string</KeyPrefixEquals> <HttpErrorCodeReturnedEquals>integer</HttpErrorCodeReturnedEquals> </Condition> <Redirect> <HttpRedirectCode>integer</HttpRedirectCode> <RedirectType>string</RedirectType> <MirrorPassQueryString>boolean</MirrorPassQueryString> <MirrorFollowRedirect>boolean</MirrorFollowRedirect> <MirrorHeaders> <PassAll>boolean</PassAll> <Pass>string</Pass> ... <Remove>string</Remove> ... <Set> <Value>string</Value> <Key>string</Key> </Set> ... </MirrorHeaders> <MirrorURL>string</MirrorURL> <EnableReplacePrefix>boolean</EnableReplacePrefix> <ReplaceKeyWith>string</ReplaceKeyWith> <PassQueryString>boolean</PassQueryString> <MirrorCheckMd5>boolean</MirrorCheckMd5> <Protocol>string</Protocol> <HostName>string</HostName> <TransparentMirrorResponseCodes>string</TransparentMirrorResponseCodes> <ReplaceKeyPrefixWith>string</ReplaceKeyPrefixWith> </Redirect> </RoutingRule> ... </RoutingRules> </WebsiteConfiguration>
JSON format:
{ "IndexDocument": { "Type": "string", "Suffix": "string", "SupportSubDir": boolean }, "ErrorDocument": { "Key": "string", "HttpStatus": "string" }, "RoutingRules": { "RoutingRule": [ { "RuleNumber": integer, "Condition": { "HttpErrorCodeReturnedEquals": integer, "KeyPrefixEquals": "string" }, "Redirect": { "MirrorURL": "string", "EnableReplacePrefix": boolean, "ReplaceKeyWith": "string", "PassQueryString": boolean, "MirrorCheckMd5": boolean, "Protocol": "string", "HostName": "string", "TransparentMirrorResponseCodes": "string", "ReplaceKeyPrefixWith": "string", "HttpRedirectCode": integer, "RedirectType": "string", "MirrorPassQueryString": boolean, "MirrorFollowRedirect": boolean, "MirrorHeaders": { "PassAll": boolean, "Pass": ["string", ...], "Remove": ["string", ...], "Set": [ { "Key": "string", "Value": "string" }, ... ] } } }, ... ] } }
For more information about supported global command-line options, see Global command-line options.
Examples
The following examples show how to enable static website hosting and configure redirection rules for a bucket named examplebucket
.
Create a configuration file named website-configuration.xml and add the following code to the configuration file:
<?xml version="1.0" encoding="UTF-8"?> <WebsiteConfiguration> <IndexDocument> <Suffix>index.html</Suffix> <SupportSubDir>true</SupportSubDir> <Type>0</Type> </IndexDocument> <ErrorDocument> <Key>error.html</Key> <HttpStatus>404</HttpStatus> </ErrorDocument> <RoutingRules> <RoutingRule> <RuleNumber>1</RuleNumber> <Condition> <KeyPrefixEquals>abc/</KeyPrefixEquals> <HttpErrorCodeReturnedEquals>404</HttpErrorCodeReturnedEquals> </Condition> <Redirect> <RedirectType>Mirror</RedirectType> <PassQueryString>true</PassQueryString> <MirrorURL>http://example.com/</MirrorURL> <MirrorPassQueryString>true</MirrorPassQueryString> <MirrorFollowRedirect>true</MirrorFollowRedirect> <MirrorCheckMd5>false</MirrorCheckMd5> <MirrorHeaders> <PassAll>true</PassAll> <Pass>myheader-key1</Pass> <Pass>myheader-key2</Pass> <Remove>myheader-key3</Remove> <Remove>myheader-key4</Remove> <Set> <Key>myheader-key5</Key> <Value>myheader-value5</Value> </Set> </MirrorHeaders> </Redirect> </RoutingRule> <RoutingRule> <RuleNumber>2</RuleNumber> <Condition> <KeyPrefixEquals>abc/</KeyPrefixEquals> <HttpErrorCodeReturnedEquals>404</HttpErrorCodeReturnedEquals> <IncludeHeader> <Key>host</Key> <Equals>test.oss-cn-beijing-internal.aliyuncs.com</Equals> </IncludeHeader> </Condition> <Redirect> <RedirectType>AliCDN</RedirectType> <Protocol>http</Protocol> <HostName>example.com</HostName> <PassQueryString>false</PassQueryString> <ReplaceKeyWith>prefix/${key}.suffix</ReplaceKeyWith> <HttpRedirectCode>301</HttpRedirectCode> </Redirect> </RoutingRule> <RoutingRule> <Condition> <HttpErrorCodeReturnedEquals>404</HttpErrorCodeReturnedEquals> </Condition> <RuleNumber>3</RuleNumber> <Redirect> <ReplaceKeyWith>prefix/${key}</ReplaceKeyWith> <HttpRedirectCode>302</HttpRedirectCode> <EnableReplacePrefix>false</EnableReplacePrefix> <PassQueryString>false</PassQueryString> <Protocol>http</Protocol> <HostName>example.com</HostName> <RedirectType>External</RedirectType> </Redirect> </RoutingRule> </RoutingRules> </WebsiteConfiguration>
Sample command:
ossutil api put-bucket-website --bucket examplebucket --website-configuration file://website-configuration.xml
Create a configuration file named website-configuration.json and add the following code to the configuration file:
{ "IndexDocument": { "Suffix": "index.html", "SupportSubDir": "true", "Type": "0" }, "ErrorDocument": { "Key": "error.html", "HttpStatus": "404" }, "RoutingRules": { "RoutingRule": [ { "RuleNumber": "1", "Condition": { "KeyPrefixEquals": "abc/", "HttpErrorCodeReturnedEquals": "404" }, "Redirect": { "RedirectType": "Mirror", "PassQueryString": "true", "MirrorURL": "http://example.com/", "MirrorPassQueryString": "true", "MirrorFollowRedirect": "true", "MirrorCheckMd5": "false", "MirrorHeaders": { "PassAll": "true", "Pass": [ "myheader-key1", "myheader-key2" ], "Remove": [ "myheader-key3", "myheader-key4" ], "Set": { "Key": "myheader-key5", "Value": "myheader-value5" } } } }, { "RuleNumber": "2", "Condition": { "KeyPrefixEquals": "abc/", "HttpErrorCodeReturnedEquals": "404", "IncludeHeader": { "Key": "host", "Equals": "test.oss-cn-beijing-internal.aliyuncs.com" } }, "Redirect": { "RedirectType": "AliCDN", "Protocol": "http", "HostName": "example.com", "PassQueryString": "false", "ReplaceKeyWith": "prefix/${key}.suffix", "HttpRedirectCode": "301" } }, { "Condition": { "HttpErrorCodeReturnedEquals": "404" }, "RuleNumber": "3", "Redirect": { "ReplaceKeyWith": "prefix/${key}", "HttpRedirectCode": "302", "EnableReplacePrefix": "false", "PassQueryString": "false", "Protocol": "http", "HostName": "example.com", "RedirectType": "External" } } ] } }
Sample command:
ossutil api put-bucket-website --bucket examplebucket --website-configuration file://website-configuration.json
Configure parameters in the following command in the JSON format:
ossutil api put-bucket-website --bucket examplebucket --website-configuration "{\"IndexDocument\":{\"Suffix\":\"index.html\",\"SupportSubDir\":\"true\",\"Type\":\"0\"},\"ErrorDocument\":{\"Key\":\"error.html\",\"HttpStatus\":\"404\"},\"RoutingRules\":{\"RoutingRule\":[{\"RuleNumber\":\"1\",\"Condition\":{\"KeyPrefixEquals\":\"abc/\",\"HttpErrorCodeReturnedEquals\":\"404\"},\"Redirect\":{\"RedirectType\":\"Mirror\",\"PassQueryString\":\"true\",\"MirrorURL\":\"http://example.com/\",\"MirrorPassQueryString\":\"true\",\"MirrorFollowRedirect\":\"true\",\"MirrorCheckMd5\":\"false\",\"MirrorHeaders\":{\"PassAll\":\"true\",\"Pass\":[\"myheader-key1\",\"myheader-key2\"],\"Remove\":[\"myheader-key3\",\"myheader-key4\"],\"Set\":{\"Key\":\"myheader-key5\",\"Value\":\"myheader-value5\"}}}},{\"RuleNumber\":\"2\",\"Condition\":{\"KeyPrefixEquals\":\"abc/\",\"HttpErrorCodeReturnedEquals\":\"404\",\"IncludeHeader\":{\"Key\":\"host\",\"Equals\":\"test.oss-cn-beijing-internal.aliyuncs.com\"}},\"Redirect\":{\"RedirectType\":\"AliCDN\",\"Protocol\":\"http\",\"HostName\":\"example.com\",\"PassQueryString\":\"false\",\"ReplaceKeyWith\":\"prefix/${key}.suffix\",\"HttpRedirectCode\":\"301\"}},{\"Condition\":{\"HttpErrorCodeReturnedEquals\":\"404\"},\"RuleNumber\":\"3\",\"Redirect\":{\"ReplaceKeyWith\":\"prefix/${key}\",\"HttpRedirectCode\":\"302\",\"EnableReplacePrefix\":\"false\",\"PassQueryString\":\"false\",\"Protocol\":\"http\",\"HostName\":\"example.com\",\"RedirectType\":\"External\"}}]}}"