S3 static pages without .html extension
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
Amazon Simple Storage Service (S3) is widely used for hosting static websites due to its scalability, durability, and affordability. A common requirement for enhancing user experience is to serve static pages without an .html extension. This approach mimics traditional website structures and is often preferred for aesthetic and SEO reasons. This article explores how to achieve it and covers related technical details.
Overview of S3 Static Website Hosting
Amazon S3 enables users to host static websites by configuring a bucket to act as a website endpoint. When a request is made, S3 retrieves and serves the stored files, typically HTML, CSS, JS, images, etc. By default, S3 serves files from the bucket with their full file paths, including extensions like .html. However, this is configurable.
Setting Up S3 Website Hosting
Here's a quick rundown of setting up S3 for static website hosting:
- Create an S3 Bucket: The bucket name should align with your desired domain (e.g.,
example.com). - Enable Static Website Hosting: Configure the bucket's properties to enable static website hosting and specify an index document and an error document.
- Upload Content: Add your HTML, CSS, and JavaScript files to the bucket.
- Configure Permissions: Modify the bucket policy to allow public access to website files.
Removing the .html Extension
To serve pages without the .html extension, there are several strategies:
1. S3 Object Names
Each object in S3 is identified by its key. By default, keys include .html for HTML pages (e.g., index.html). By structuring your keys properly, you can serve content without explicit extensions.
Example:
Instead of uploading a file as page1.html:
- Use
page1/with an object keyindex.htmlinside it.
2. AWS CloudFront
AWS CloudFront, a content delivery network (CDN), can rewrite URLs for you. Implementing Lambda@Edge with CloudFront allows requests to be redirected appropriately:
- Lambda@Edge Function: Set up a request handler function that modifies the
URIto match S3 key structure.
3. Route 53 Alias Records
Another advanced approach involves AWS Route 53 with alias records, which essentially point to another CloudFront distribution or ELB that can handle file requests intelligently.
SEO and User Experience Benefits
- Improved Readability: URLs are more user-friendly without
.html, making them easier to read and type. - SEO Optimization: Clean URLs are generally better received by search engines, potentially improving page rank.
Considerations
- Caching: Ensure appropriate cache settings in CloudFront to manage versions effectively.
- Security: Ensure bucket policies are carefully reviewed to prevent unintentional public access to sensitive data.
- Cost: Evaluate potential costs associated with CloudFront or AWS Lambda, particularly at scale.
Summary Table
| Method | Key Features | Considerations |
| Object Naming | Simple URL structure No additional costs | Manual management only |
| AWS CloudFront & Lambda@Edge | URL rewriting Highly customizable Leveraging cache | Lambda costs Complex setup |
| Route 53 & Alias Records | Direct DNS-based routing Utilizes AWS services | Limited to AWS ecosystem |
Conclusion
Serving S3-hosted static pages without an .html extension can significantly enhance user experience and SEO. Amazon S3, combined with services like AWS CloudFront and Route 53, offers robust solutions, but they come with their own sets of challenges and cost considerations. Understanding these options and implementing the right mix based on specific website requirements will help you achieve a cleaner, more effective URL management strategy.
Related reading
- S3 Static Website Hosting Route All Paths to Index.html
- S3 Static Website Hosting when Bucketname is taken?
- S3 storing JSON vs DynamoDB
- S3 Sync vs. Cross-region Replication
- s3.getObject.createReadStream How to catch the error?
- SageMaker and TensorFlow 2.0
- Same partition key's data distribution in DynamoDB
- Save AWS Cognito Users in DynamoDB

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.