Static Website

Last updated: 2020-03-20 09:44:32

PDF

This document provides an overview of API on static websites and sample SDK code.

API Operation name pedagogical operation
PUT Bucket website Setting up a Static Website Set Bucket's static website configuration
GET Bucket website Query static site configuration Query Bucket's static website configuration
DELETE Bucket website Delete static site configuration Delete Bucket's static website configuration

Setting up a Static Website

Function description

PUT Bucket website is used to configure a static website for Bucket.

Method prototype

public Guzzle\Service\Resource\Model PutBucketWebsite(array $args = array());

Request Sample

try {
    $result = $cosClient->putBucketWebsite(array(
        'Bucket' => 'examplebucket-1250000000', 
        'IndexDocument' => array(
            'Suffix' => 'index.html',
        ),
        'RedirectAllRequestsTo' => array(
            'Protocol' => 'https',
        ),
        'ErrorDocument' => array(
            'Key' => 'Error.html',
        ),
        'RoutingRules' => array(
            array(
                'Condition' => array(
                    'HttpErrorCodeReturnedEquals' => '405',
                ),
                'Redirect' => array(
                    'Protocol' => 'https',
                    'ReplaceKeyWith' => '404.html',
                ),
            ),  
            // ... repeated
        ),  
    )); 
    print_r($result);
} catch (\Exception $e) {
    echo "$e\n";
}

Parameter description

Parameter name Parent node Description Type Is it required?
Bucket None Set the Bucket of the static website in BucketName-APPID format. For more information, please see Naming convention String Yes
IndexDocument None Index document Array Yes
Suffix IndexDocument Specify an indexed document String Yes
ErrorDocument None Error document Array No
Key ErrorDocument Specify generic error return String No
RedirectAllRequestsTo None Redirect all requests Array No
Protocol RedirectAllRequestsTo Protocol who specifies the site-wide redirection can only be set to https String No
RoutingRules None Set redirection rules. Set a maximum of 100 RoutingRule Array No
RoutingRule RoutingRules Set single redirection rules, including prefix matching redirection and error code redirection Array No
Condition RoutingRule Specify the conditions under which redirection occurs. Only one prefix matching redirection and error code redirection can be specified. Array No
HttpErrorCodeReturnedEquals Condition Specify redirect error code. Only 4XX error code can be configured. Priority is higher than ErrorDocument. Interger No
KeyPrefixEquals Condition Specifies the path to the prefix redirection, replacing the specified folder/ String No
Redirect RoutingRule Specify specific replacement rules for redirection when the redirection conditon is satisfied Array No
ReplaceKeyWith Redirect Replace the entire Key with the specified content String No
ReplaceKeyPrefixWith Redirect Replace the prefix that matches to the specified content, and the Conditon can only be set to KeyPrefixEquals. String No

Query static site configuration

Function description

GET Bucket website is used to query static website configuration information with Bucket and Associate.

Method prototype

public Guzzle\Service\Resource\Model GetBucketWebsite(array $args = array());

Request Sample

try {
    $result = $cosClient->getBucketWebsite(array(
        'Bucket' => 'examplebucket-1250000000', 
    )); 
    print_r($result);
} catch (\Exception $e) {
    echo "$e\n";
}

Parameter description

Parameter name Description Type
Bucket Query Bucket configured for static website. The format is BucketName-APPID,. For more information, please see Naming convention String

Return an example of the result

GuzzleHttp\Command\Result Object
(
    [RedirectAllRequestsTo] => Array
        (
            [Protocol] => https
        )

    [IndexDocument] => Array
        (
            [Suffix] => index.html
        )

    [ErrorDocument] => Array
        (
            [Key] => Error.html
        )

    [RoutingRules] => Array
        (
            [0] => Array
                (
                    [Condition] => Array
                        (
                            [HttpErrorCodeReturnedEquals] => 405
                        )

                    [Redirect] => Array
                        (
                            [Protocol] => https
                            [ReplaceKeyWith] => 404.html
                        )

                )

        )
    [RequestId] => NWRmMzQ3YjlfMTlhYTk0MGFfNzMzYl84YWIy****
)

Return result description

Parameter name Description Type
Bucket Bucket's name is in BucketName-APPID format. For more information, please see Naming convention String
IndexDocument Index document Array
Suffix Specify an indexed document String
ErrorDocument Error document Array
Key Specify generic error return String
RedirectAllRequestsTo Redirect all requests Array
Protocol Protocol who specifies the site-wide redirection can only be set to https String
RoutingRules Set redirection rules. Set a maximum of 100 RoutingRule Array
RoutingRule Set single redirection rules, including prefix matching redirection and error code redirection Array
Condition Specify the conditions under which redirection occurs. Only one prefix matching redirection and error code redirection can be specified. Array
HttpErrorCodeReturnedEquals Specify redirect error code. Only 4XX error code can be configured. Priority is higher than ErrorDocument. Interger
KeyPrefixEquals Specifies the path to the prefix redirection, replacing the specified folder/ String
Redirect Specify specific replacement rules for redirection when the redirection conditon is satisfied Array
ReplaceKeyWith Replace the entire Key with the specified content String
ReplaceKeyPrefixWith Replace the prefix that matches to the specified content, and the Conditon can only be set to KeyPrefixEquals. String

Delete static site configuration

Function description

DELETE Bucket website is used to delete the static website configuration in Bucket.

Method prototype

public Guzzle\Service\Resource\Model DeleteBucketWebsite(array $args = array());

Request Sample

try {
    $result = $cosClient->deleteBucketWebsite(array(
        'Bucket' => 'examplebucket-1250000000', 
    )); 
    print_r($result);
} catch (\Exception $e) {
    echo "$e\n";
}

Parameter description

Parameter name Description Type
Bucket Bucket, whose static website configuration is deleted, is in BucketName-APPID format. For more information, please see Naming convention String