Dev.to
7/24/2026

AWS S3 + CloudFront Subdirectory Hosting: Architecture & Edge Cases
Short summary
A practical guide to edge cases when hosting static sites on AWS S3 with CloudFront, covering HSTS caching issues, directory routing gaps, CloudFront Function event timing, and relative asset path resolution. Each problem is paired with its root cause and a concrete fix, including a CloudFront Function that handles trailing-slash redirects and index.html rewrites. Useful for anyone deploying documentation or static assets through this stack.
- •Browser HSTS caching can mask infrastructure fixes—clear via chrome://net-internals
- •CloudFront Default Root Object only applies to distribution root, not subdirectories
- •A CloudFront Function on Viewer Request can handle trailing-slash redirects and index.html rewrites
Generated with AI, which can make mistakes.
Is this a good recommendation for you?



