Static websites consist only of static content, including scripts such as JavaScript
code that is run on the client. You can use the static website hosting feature to
host your static website on an Object Storage Service (OSS) bucket and use the endpoint
of the bucket to access the website.
Usage notes
For security reasons, starting from August 13, 2018 for regions inside mainland China,
and September 25, 2019 for regions outside China, when you access web page objects
whose MIME type is text/html and whose name extension is HTM, HTML, JSP, PLG, HTX,
or STM by using browsers:
- If you use the default endpoint of the bucket to access the objects, the following
header is automatically contained in the response:
Content-Disposition:'attachment=filename;'
. In this case, the web page objects are downloaded as attachments. The content of
the object cannot be previewed.
- If you use a custom domain name mapped to the bucket to access the objects, the
Content-Disposition:'attachment=filename;'
header is not contained in the response. In this case, you can preview the object
content if your browser supports preview of web page objects. For more information
about how to map a custom domain name to a bucket, see Map custom domain names.
For more information, see Overview.
Scenarios
In this topic, a bucket named examplebucket is used in the following example to show
how to enable static website hosting for a bucket. The following structure shows the
objects and directories in examplebucket:
examplebucket
├── index.html
├── error.html
├── example.txt
└── subdir/
└── index.html
The first example shows how to disable subdirectory homepage when you configure static
website hosting for examplebucket. In this case, when you access the subdir/ directory
of examplebucket, the default homepage object named index.html in the root directory
of examplebucket is returned instead of the object named index.html in the subdir/
directory. In addition, if you access an object that does not exist in examplebucket,
the specified default 404 page is returned. For more information, see Configure static website hosting and disable subdirectory homepage.
The second example shows how to enable subdirectory homepage and configure a subdirectory
404 rule when you configure static website hosting for examplebucket. In this case,
when you access the subdir/ directory of examplebucket, the default homepage object
named index.html in the /subdir directory of examplebucket is returned. In addition,
if you access an object that does not exist in examplebucket, a result is returned
based on the specified subdirectory 404 rule together with the specified default 404
page. For more information, see Configure static website hosting and enable subdirectory homepage.
Configure static website hosting and disable subdirectory homepage
- Log on to the OSS console.
- Click Buckets, and then click the name of the target bucket.
- In the left-side navigation pane, choose . Click Configure in the Static Pages section. Configure the parameters listed in the following table.

Parameter |
Description |
Default Homepage |
Configure the default homepage that appears when you use a browser to access the static
website hosted on the OSS bucket. In this example, set this parameter to index.html.
|
Subfolder Homepage |
Specify whether to enable subdirectory homepage for the bucket. In this example, select
Disable. In this case, when you access the root directory of the bucket or a subdirectory
whose URL ends with a forward slash (/), the default homepage object in the root directory
of the bucket is returned.
|
Default 404 Page |
Specify the error page that is returned when the object that you want to access does
not exist in the bucket and a 404 HTTP status code is returned. Only an object in
the root directory of the bucket can be specified as the default 404 page. In this
example, set this parameter to error.html.
|
Error Page Status Code |
Set the HTTP status code that is returned with the error page. Valid values: 404 and 200.
|
- Click Save.
Configure static website hosting and enable subdirectory homepage
- Log on to the OSS console.
- Click Buckets, and then click the name of the target bucket.
- In the left-side navigation pane, choose . In the Static Pages section, click Configure. Configure the parameters listed in the following table.

Parameter |
Description |
Default Homepage |
Configure the default homepage that appears when you use a browser to access the static
website hosted on the OSS bucket. In this example, set this parameter to index.html.
|
Subfolder Homepage |
Select Enable. After you enable subdirectory homepage for a bucket, if you access the root directory
of the bucket, the default homepage in the root directory is returned. If you access
a subdirectory whose URL ends with a forward slash (/), the default homepage in the
subdirectory is returned. For example, if you access https://examplebucket.oss-cn-hangzhou.aliyuncs.com/subdir/ , the default homepage object index.html in the subdir/ directory is returned.
|
Subfolder 404 Rule |
Configure the subdirectory 404 rule for the bucket. When you access an object that
does not exist in the bucket, OSS returns different results based on the specified
subdirectory 404 rule. For example, if you use the URL https://examplebucket.oss-cn-hangzhou.aliyuncs.com/exampledir to access an object named exampledir, which does not exist in examplebucket, OSS returns different results based on the
value that you set for this parameter. Default value: Redirect.
- Redirect: OSS checks whether the exampledir/index.html object exists.
- If this object exists, OSS returns 302 and redirects the request to
https://examplebucket.oss-cn-hangzhou.aliyuncs.com/exampledir/index.html .
- If this object does not exist, OSS returns 404 and checks whether the
https://examplebucket.oss-cn-hangzhou.aliyuncs.com/error.html object exists. If this object also does not exist, OSS returns 404 status code.
- NoSuckKey: OSS returns 404 and checks whether the
https://examplebucket.oss-cn-hangzhou.aliyuncs.com/error.html object exists.
- Index: OSS checks whether the exampledir/index.html object exists.
- If this object exists, OSS returns 200 and the content of this object.
- If this object does not exist, OSS checks whether the
https://examplebucket.oss-cn-hangzhou.aliyuncs.com/error.html object exists.
|
Default 404 Page |
Specify the error page that is returned when the object that you want to access does
not exist in the bucket and a 404 HTTP status code is returned. Only an object in
the root directory of the bucket can be specified as the default 404 page. In this
example, set this parameter to error.html.
|
Error Page Status Code |
Set the HTTP status code that is returned with the error page. Valid values: 404 and 200.
|
- Click Save.
Create and upload a default homepage object
If you set the default homepage to index.html when you configure static website hosting
for examplebucket, you must upload an object named index.html to the root directory
of examplebucket. If you enable subdirectory homepage for examplebucket, you must
also upload index.html to the subdir/ directory of examplebucket.
- Create a local file named index.html. The following example shows the content of index.html:
<html>
<head>
<title>My Website Home Page</title>
<meta charset="utf-8">
</head>
<body>
<p>Now hosted on OSS.</p>
</body>
</html>
- Save index.html to the local computer.
- Upload index.html to the root directory and subdir/ directory of examplebucket. You
must set the access control list (ACL) of index.html to public read.
Create and upload a default 404 page
If you set the default 404 page to error.html when you configure static website hosting
for examplebucket, you must upload an object named error.html to the root directory
of examplebucket.
- Create a local file named error.html. The following example shows the content of error.html:
<html>
<head>
<title>Hello OSS!</title>
<meta charset="utf-8">
</head>
<body>
<p>This is error 404 page.</p>
</body>
</html>
- Save error.html to the local computer.
- Upload error.html to the root directory of examplebucket. You must set the ACL of
error.html to public read.
Disable static website hosting
If you no longer need to use the configurations of static website hosting, perform
the following steps to disable the static website hosting feature:
- Log on to the OSS console.
- Click Buckets, and then click the name of the target bucket.
- In the left-side navigation pane, choose . In the Static Pages, click Configure.
- Remove the configurations of the Default Homepage and Default 404 Page parameters
and click Save.
If a similar figure is returned, the static website hosting feature is disabled.
