VK Cloud logo

Static site hosting

Static site hosting — an additional option for a bucket in VK Object Storage that extends the capabilities of access to static content. Without this option, the content of an object is retrieved via a URL corresponding to its key. Static site hosting allows combining static content with redirection rules, as well as specifying an index page (for example, index.html) and an error page returned on request errors (for example, 404).

Usage examples:

  • a business card website,
  • a personal blog,
  • landing pages,
  • request redirection,
  • documentation.

A static website based on VK Object Storage may consist of:

  • static content: HTML, CSS, media files (images, audio, video), documents (PDF, TXT) and other formats viewable in a browser.
  • JavaScript script files that do not require server-side processing: expandable menus, tabs, accordions, etc.

After the configuration is installed, the static website is available at:

https://<BUCKET_NAME>.hb-website.<ENDPOINT_HOSTNAME>/<PREFIX>

Here:

  • <BUCKET_NAME> — the name of the bucket for which the static website configuration was installed;

  • <ENDPOINT_HOSTNAME> — the host name of the VK Object Storage service, must match the region of the account:

    • hb.vkcloud-storage.ru or hb.ru-msk.vkcloud-storage.ru — the domain of the Moscow region;
    • hb.kz-ast.vkcloud-storage.ru — the domain of the Kazakhstan region.
  • <PREFIX> — the key prefix of the index page object. Can be empty.

Static website JSON configuration

The configuration is provided in JSON format and is used when managing the configuration via AWS CLI.

General structure of the configuration:

{   "IndexDocument": {           // Index page      "Suffix": "string"   },   "ErrorDocument": {           // Error page      "Key": "string"   },   "RoutingRules": [            // Redirection rules      {          "Condition": {              "HttpErrorCodeReturnedEquals": "string",         "KeyPrefixEquals": "string"         },         "Redirect": {             "HostName": "string",         "HttpRedirectCode": "string",         "Protocol": "http"|"https",         "ReplaceKeyPrefixWith": "string",         "ReplaceKeyWith": "string"         }      }   ...   ],    "RedirectAllRequestsTo": {   // Unconditional redirection of all requests    "HostName": "string",    "Protocol": "http"|"https"    }}

Index page configuration parameters

IndexDocument — a configuration element that specifies the index page.

Compatibility of IndexDocument with other configuration elements:

Configuration element

Compatibility

Functionality

ErrorDocument

Static site hosting

Error page

RoutingRules

Static site hosting

Redirection rules

RedirectAllRequestsTo

Static site hosting

Unconditional redirection

IndexDocument parameters:

Name

Description

IndexDocument — an element of the object format

Suffix

The suffix (name) for the index page object.

Format: string.

When the website page is opened, the content of the object with the specified value will be loaded.

Cannot contain the / character.

Full path: IndexDocument → Suffix

Error page configuration parameters

ErrorDocument — a configuration element that specifies the error page. It is used together with the IndexDocument configuration element, which specifies the index page.

For example, when opening a non-existent page, a 404 error will occur. Instead of the non-existent page, the content of the specified object, for example errordoc/file.html, will be loaded.

Compatibility of ErrorDocument with other configuration elements:

Configuration element

Compatibility

Functionality

IndexDocument (required)

Static site hosting

Index page

RoutingRules

Static site hosting

Redirection rules

RedirectAllRequestsTo

Static site hosting

Unconditional redirection

ErrorDocument parameters:

Name

Description

ErrorDocument — an element of the object format.

Key

The full key of the error page object.

Format: string.

For an HTTP response 4XX for which there is no redirection rule in RoutingRules, the content from the object with the specified key will be loaded. No redirection is performed.

Full path: ErrorDocument → Key

Redirection rules configuration parameters

RoutingRules — a configuration element that specifies redirection rules. It is used together with the IndexDocument configuration element, which specifies the index page.

Compatibility of RoutingRules with other configuration elements:

Configuration element

Compatibility

Functionality

IndexDocument (required)

Static site hosting

Index page

ErrorDocument

Static site hosting

Error page

RedirectAllRequestsTo

Static site hosting

Unconditional redirection

RoutingRules parameters:

Name

Description

RoutingRules — redirection rules in the array format:

  • Each element of the RoutingRules[i] array is a separate rule in the object format, which specifies the Condition and the Redirect parameters.
  • The rules are applied in the order in which they are specified in the RoutingRules array.
  • If a rule has triggered, a new request is formed, to which the RoutingRules rules are also applied

Condition

The conditions for the rule to trigger, in the object format.

If no condition is specified, the redirection will trigger for all requests.

Full path: RoutingRules[i] → Condition

HttpErrorCodeReturnedEquals

The error code in the 4XX or 5XX format at which the rule triggers.

If used together with KeyPrefixEquals, the rule will trigger only when both conditions are met.

Format: string.

Upon receiving an HTTP response with the specified error code, the rule specified in RoutingRules[i] → Redirect triggers.

Full path: RoutingRules[i] → Condition → HttpErrorCodeReturnedEquals

KeyPrefixEquals

The key prefix of the requested object. If a full key is specified, the rule will apply only to that object.

If used together with HttpErrorCodeReturnedEquals, the rule will trigger only when both conditions are met.

Format: string.

When opening a page with the specified key or prefix, the rule specified in RoutingRules[i] → Redirect triggers.

Full path: RoutingRules[i] → Condition → KeyPrefixEquals

Redirect

Specifies the redirection settings in the object format.

Full path: RoutingRules[i] → Redirect

HostName

The name of the host to which the redirection will be performed.

Format: string.

Can be used together with other Redirect parameters.

If the value is not specified, the host name will not be changed.

Full path: RoutingRules[i] → Redirect → HostName

HttpRedirectCode

The HTTP code in the 3XX format that will be returned upon redirection.

Format: string.

If the value is not specified, the default response code 301 is used.

Can be used together with other Redirect parameters.

Full path: RoutingRules[i] → Redirect → HttpRedirectCode

Protocol

Specified when the protocol needs to be changed.

Format: string.

Possible values: http, https.

Can be used together with other Redirect parameters.

Full path: RoutingRules[i] → Redirect → Protocol

ReplaceKeyPrefixWith

The object key prefix to replace the prefix of the requested object with.

Format: string.

If an empty string is specified, the new request will have no prefix.

Usually used together with RoutingRules[i] → Condition → KeyPrefixEquals to redirect a group of objects from one prefix to another.

Can be used together with the HostName, HttpRedirectCode and Protocol parameters.

Incompatible with the ReplaceKeyWith parameter.

Full path: RoutingRules[i] → Redirect → ReplaceKeyPrefixWith

ReplaceKeyWith

The key of the object to redirect to.

Format: string.

Can be used together with the HostName, HttpRedirectCode and Protocol parameters.

Incompatible with the ReplaceKeyPrefixWith parameter.

Full path: RoutingRules[i] → Redirect → ReplaceKeyWith

Unconditional redirection configuration parameters

RedirectAllRequestsTo — a configuration element that specifies unconditional redirection rules for all website requests.

Compatibility of RedirectAllRequestsTo with other configuration elements:

Configuration element

Compatibility

Functionality

IndexDocument

Static site hosting

Index page

ErrorDocument

Static site hosting

Error page

RoutingRules

Static site hosting

Redirection rules

RedirectAllRequestsTo parameters:

Name

Description

RedirectAllRequestsTo — an element of the object format that specifies unconditional redirection rules for all website requests

HostName

The name of the host to which the redirection will be performed. Required parameter.

Format: string.

Can be used together with Protocol.

Full path: RedirectAllRequestsTo → HostName

Protocol

Specified when the protocol needs to be changed.

Format: string.

Possible values: http, https.

Can be used together with HostName.

Full path: RedirectAllRequestsTo → Protocol

Configuration examples

Some parameters are incompatible with each other, so the number of their combinations is limited.

  • Only the index page IndexDocument:

    {    "IndexDocument": {    "Suffix": "index.html"    }}
  • The index page IndexDocument and the error page ErrorDocument:

    {    "IndexDocument": {    "Suffix": "index.html"    },    "ErrorDocument": {    "Key": "error.html"    }}
  • The index page IndexDocument and the redirection rules RoutingRules:

    {    "IndexDocument": {    "Suffix": "index.html"    },    "RoutingRules": [    {        "Condition": {        "KeyPrefixEquals": "docs/"        },        "Redirect": {        "ReplaceKeyPrefixWith": "documents/",        "HttpRedirectCode": "301"        }    }    ]}

    In this example, all requests with the docs/ prefix will be redirected to documents/ and return the HTTP response code 301.

  • The index page IndexDocument, the error page ErrorDocument and the redirection rules RoutingRules:

    {    "IndexDocument": {    "Suffix": "index.html"    },    "ErrorDocument": {    "Key": "error.html"    },    "RoutingRules": [    {        "Condition": {        "HttpErrorCodeReturnedEquals": "404"        },        "Redirect": {        "ReplaceKeyWith": "index.html",        "HttpRedirectCode": "302"        }    }    ]}

    In this example, upon an HTTP 404 error, the request is redirected to index.html; for other errors, the content of error.html is returned.

  • Unconditional redirection RedirectAllRequestsTo for all requests:

    {    "RedirectAllRequestsTo": {    "HostName": "example.com",    "Protocol": "https"    }}

    In this example, all requests are redirected to example.com via the https protocol. The response always returns the code 301.

Was this article helpful?