Amazon S3 static hosting with Namecheap DNS - How to correctly route non-www prefixed URL
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
The tricky part of S3 static hosting is not the www subdomain. It is the root domain, also called the zone apex, such as example.com. S3 website endpoints are hostnames, not fixed IP addresses, so you cannot solve the apex problem with a normal A record pointing at S3 directly.
That is why the clean answer is usually one of two designs: serve the site from www and redirect the apex, or put CloudFront in front so the root domain can be mapped properly. Trying to force a plain apex A record to raw S3 hosting is where most setups go wrong.
Recommended Pattern
The most practical layout is:
- bucket
www.example.comhosts the actual site - bucket
example.comperforms a redirect tohttps://www.example.com - DNS points
wwwto the site host - DNS handles the apex through redirect or an alias-capable front end
This avoids ambiguity and keeps the root domain behavior explicit.
S3 Website Configuration
For the content bucket:
- create bucket
www.example.com - enable static website hosting
- upload
index.htmland other assets
For the redirect bucket:
- create bucket
example.com - enable static website hosting
- choose "redirect requests"
- target
www.example.com
The redirect bucket is not where the site files live. It exists only to forward apex traffic.
DNS with Namecheap
For www, a CNAME-style record is straightforward because it is not the apex:
The exact S3 website hostname depends on the AWS region.
For the root domain, the important rule is this:
- a normal DNS apex cannot use an ordinary CNAME
So the apex solution depends on what your DNS provider supports. If your provider offers ALIAS or ANAME-like behavior, use that. If not, a safer pattern is to use a redirect service or place CloudFront in front of the site and point the apex at CloudFront through a supported mechanism.
Why CloudFront Often Wins
CloudFront solves multiple issues at once:
- custom domain support
- HTTPS with ACM certificates
- clean routing for both
example.comandwww.example.com - caching and CDN delivery
A minimal architecture is:
- S3 stores the static files
- CloudFront serves them
- DNS points both apex and
wwwat CloudFront
If you need HTTPS, this is usually the better production design because S3 website endpoints alone do not give you the same flexibility at the custom-domain edge.
Example Redirect Bucket Policy
For a public website bucket, you still need readable objects:
That policy belongs on the content bucket, not on the redirect logic itself.
Practical Decision Rule
Use this rule:
- if you only need simple HTTP website hosting,
wwwplus apex redirect is fine - if you need a professional custom-domain setup with HTTPS, put CloudFront in front
That keeps the design aligned with what DNS and S3 actually support.
Common Pitfalls
- Trying to point a plain apex
Arecord directly at an S3 website endpoint. - Hosting the site in the apex bucket and expecting
wwwand root routing to sort themselves out. - Forgetting that the S3 website endpoint is region-specific.
- Building a public website on raw S3 hosting and then later discovering HTTPS requirements.
- Mixing "redirect bucket" and "content bucket" responsibilities in one bucket.
Summary
- The root domain is the hard part of S3 static hosting, not the
wwwrecord. - A normal apex cannot use a plain CNAME to an S3 website hostname.
- The practical pattern is
wwwfor the site and apex redirect, or CloudFront for both. - S3 redirect buckets and content buckets should have separate roles.
- If HTTPS matters, CloudFront is usually the right front end.
Related reading
- Amazon S3 static site serves old contents
- Amazon S3 upload file and get URL
- Amazon S3 What are considered PUT/COPY/POST/LIST request?
- Amazon S3 Write Only access
- Amazon Simple Email Service SES - Should I use SMTP Interface or SES API?
- Amazon SNS Platform credentials are invalid when re-entering a GCM API key that previously worked
- amazon ses smtp python usage
- Amazon SimpleDB vs Amazon 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.