The website command is used to add, modify, query, or delete static website hosting, redirection-based back-to-origin, and mirroring-based back-to-origin configurations of a bucket.

Note
  • The commands described in this topic apply to Linux. To use the commands in other systems, replace ./ossutil in the command with the actual executable program name. For example, you can use the help command in 32-bit Windows systems by running ossutil32.exe help.
  • For more information about static website hosting, see Static website hosting.
  • For more information about back-to-origin, see Manage back-to-origin configurations.

Command syntax

  • Add or modify website-related configurations
    ./ossutil website --method put oss://bucket  local_xml_file

    ossutil is used to read website-related configurations from the local_xml_file configuration file and add the rules obtained from the configuration file for the bucket. If the bucket already has website-related configurations, the new configurations will overwrite the existing configurations.

    The local_xml_file configuration file is in XML format as follows:
    • The IndexDocument field specifies the default homepage.
    • The ErrorDocument field specifies the default 404 page.
    • The RoutingRules field configures redirection- and mirroring-based back-to-origin rules. For more information,see Configure back-to-origin rules.
    You can set the preceding fields as required. The following code provides an example on 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 are saved as a local file. If this parameter is not specified, ossutil displays 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 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: adds or modifies website-related configurations.
  • get: queries website-related configurations.
  • delete: deletes website-related configurations.
--loglevel Specifies the log level. The default value is null and specifies that no log file is generated. Valid values:
  • info: generates prompt logs.
  • debug: generates detailed logs that contain HTTP request and response information.
--proxy-host Specifies the URL of the proxy server. HTTP, HTTPS, and SOCKS5 proxies are supported. An example of the URL is http://120.79. **.**:3128 or socks5://120.79. **. **:1080.
--proxy-user Specifies the username for the proxy server. The default value is null.
--proxy-pwd Specifies the password for the proxy server. The default value is null.
Note For more information about common options, see View all supported options.