I want to use Amazon Simple Storage Service (Amazon S3) to host a static website and set up website redirection.
Resolution
First, activate static website hosting for your Amazon S3 bucket. Then, configure redirects rules to another bucket or domain.
Note: For enterprise deployments, it's a best practice to use AWS Amplify Hosting to deploy a static website from an Amazon S3 bucket. Additional charges might apply to deploy your S3 applications to AWS Amplify Hosting. For more information, see AWS Amplify pricing.
Configure static website hosting on your S3 bucket endpoint
Complete the following steps:
- Open the Amazon S3 console.
- In the navigation pane, choose Buckets.
- Select the S3 bucket that you want to use for static website hosting.
- Choose the Properties tab.
- In Static website hosting, choose Edit, and then choose Enable.
- For Hosting type, choose Host a static website.
- For Index document, enter the home or default page of the website, for example index.html.
Note: Don't begin your index name with a trailing slash "/". For example, don't use: /index.html. Instead, use index.html in all lowercase. For more information, see Why is a trailing slash added to the URL when I use the Amazon S3 static website redirection feature?
- Choose Save changes.
- Test your website endpoint.
Note: If you receive an Access Denied error message, then see Why did I get an "Access Denied" error when I used the Amazon S3 static website hosting endpoint?
(Optional) Configure permissions for your static website
To grant public read access to your static website, you can turn on S3 Block Public Access. If your bucket contains objects that you don't own, then you might also need to add an access control list (ACL) that grants read access. If you don't want to turn on S3 Block Public Access, then create an Amazon CloudFront distribution to serve your static website.
For more information, see Setting permissions for website access.
Note: By default, the S3 Block Public Access feature is turned off. It's a best practice to keep S3 Block Public Access turned off.
Configure redirect rules for your static website
Complete the following steps:
- Choose the Properties tab of your S3 bucket.
- In Redirection rules, enter the following JSON rule:
[
{
"Condition": {
"KeyPrefixEquals": "images/"
},
"Redirect": {
"ReplaceKeyWith": "folderdeleted.html"
}
}
]
The preceding example JSON rule redirects requests for an object with the images/ key prefix to folderdeleted.html.
- Choose Save changes.
Note: To create redirection rules on the Amazon S3 console, you must use JSON. For more example redirect rules, see Redirection rules examples.
You can also use Amazon Route 53 to route domain traffic to an S3 bucket.
Related information
Why is my static website hosted on Amazon S3 and served through CloudFront down?
Why is my static website on Amazon S3 still accessible from public IP addresses even though I restricted access to a specific Amazon VPC?