The website command is used to add, modify, query, or delete static website hosting and back-to-origin configurations.

Note

Command syntax

  • Add or modify website-related configurations
    ./ossutil website --method put oss://bucket  local_xml_file
    ossutil is used to read or write website-related configurations from or to local_xml_file. If the bucket has website-related configurations, new configurations will overwrite the existing configurations.
    Note The local_xml_file configuration file is in the XML format as follows:
    • The IndexDocument field is used to specify the default homepage.
    • The ErrorDocument field is used to specify the default 404 page.
    • The RoutingRules field is used to configure back-to-origin rules in the redirection or mirroring mode.
    You can set the preceding fields as required. The following code provides an example of how to set these fields:
    <? xml version="1.0" encoding="UTF-8"? >
     <WebsiteConfiguration>
         <IndexDocument>
             <Suffix>index.html</Suffix>
         </IndexDocument>
         <ErrorDocument>
             <Key>error.html</Key>
         </ErrorDocument>
         <RoutingRules>
             <RoutingRule>
                 <RuleNumber>1</RuleNumber>
                 <Condition>
                     <KeyPrefixEquals>abc/</KeyPrefixEquals>
                     <HttpErrorCodeReturnedEquals>404</HttpErrorCodeReturnedEquals>
                 </Condition>
                 <Redirect>
                     <RedirectType>Mirror</RedirectType>
                     <PassQueryString>true</PassQueryString>
                     <MirrorURL>http://www.test.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>www.test.com</HostName>
                   <PassQueryString>false</PassQueryString>
                   <ReplaceKeyWith>prefix/${key}.suffix</ReplaceKeyWith>
                   <HttpRedirectCode>301</HttpRedirectCode>
                 </Redirect>
             </RoutingRule>
         </RoutingRules>
     </WebsiteConfiguration>
  • Obtain website-related configurations
    ./ossutil website --method get oss://bucket  [local_xml_file]

    The local_xml_file parameter specifies the name of the configuration file. If this parameter is specified, website-related configurations will be saved as a local file. If this parameter is not specified, ossutil will display website-related configurations.

  • Delete website-related configurations
    ./ossutil website --method delete oss://bucket

Examples

  • Add default homepage and default 404 page configurations for static website hosting
    ./ossutil website --method put oss://bucket1  /file/website.xml
    The content of the website.xml file is as follows:
    <? xml version="1.0" encoding="UTF-8"? >
     <WebsiteConfiguration>
         <IndexDocument>
             <Suffix>test.html</Suffix>
         </IndexDocument>
         <ErrorDocument>
             <Key>errortest.html</Key>
         </ErrorDocument>
    </WebsiteConfiguration>
  • Add mirroring-based back-to-origin configurations
    ./ossutil website --method put oss://bucket1  /file/website.xml
    The content of the website.xml file is as follows:
    <? xml version="1.0" encoding="UTF-8"? >
    <WebsiteConfiguration>
    <RoutingRules>
             <RoutingRule>
                 <RuleNumber>1</RuleNumber>
                 <Condition>
                     <KeyPrefixEquals>abc/</KeyPrefixEquals>
                     <HttpErrorCodeReturnedEquals>404</HttpErrorCodeReturnedEquals>
                 </Condition>
                 <Redirect>
                     <RedirectType>Mirror</RedirectType>
                     <PassQueryString>true</PassQueryString>
                     <MirrorURL>http://www.aliyun.com/</MirrorURL>
                     <MirrorPassQueryString>true</MirrorPassQueryString>
                     <MirrorFollowRedirect>true</MirrorFollowRedirect>
                     <MirrorCheckMd5>false</MirrorCheckMd5>
                     <MirrorHeaders>
                       <PassAll>true</PassAll>
                       <Pass>myheader1</Pass>
                       <Pass>myheader2</Pass>
                       <Remove>myheader3</Remove>
                       <Remove>myheader4</Remove>
                       <Set>
                         <Key>myheader5</Key>
                         <Value>myheader5</Value>
                       </Set>
                     </MirrorHeaders>
                 </Redirect>
             </RoutingRule>
    <RoutingRules>
    </WebsiteConfiguration>
  • Obtain website-related configurations
    ./ossutil website --method get oss://bucket1  /file/website.xml
  • Delete website-related configurations
    ./ossutil website --method delete oss://bucket1  

Common options

The following table describes the options you can add to the website command.
Option Description
--method Specifies the HTTP request method. Valid values:
  • put: creates or modifies configurations.
  • get: obtains configurations.
  • delete: deletes configurations.
--loglevel Specifies the log level. The default value is null, indicating that no log files are generated. Valid values:
  • info: generates prompt logs.
  • debug: generates detailed logs that contain corresponding HTTP request and response information.
--proxy-host Specifies the URL of the proxy server. HTTP, HTTPS, and SOCKS5 are supported. An example of the URL is http://120.79. **.**:3128 or socks5://120.79. **. **:1080.
--proxy-user Specifies the username of the proxy server. The default value is null.
--proxy-pwd Specifies the password of the proxy server. The default value is null.
Note For more information about common options, see View all supported options.