CloudFront's "Default Root Object" only applies to /, not subdirectories. When accessing /whats-new, CloudFront doesn't append index.html.
Use a CloudFront Function to rewrite requests. Steps:
Solution: Add a CloudFront Function
- Create a CloudFront Function:
- Go to CloudFront Console → Functions
- Click "Create function"
- Name: append-index-html (or similar)
- Function code:
function handler(event) {
var request = event.request;
var uri = request.uri;
// Check whether the URI is missing a file name.
if (uri.endsWith('/')) {
request.uri += 'index.html';
}
// Check whether the URI is missing a file extension.
else if (!uri.includes('.')) {
request.uri += '/index.html';
}
return request;
}- Associate the Function with your Distribution:
- Go to your CloudFront distribution → Behaviors
- Edit the default behavior (or create/edit the behavior for your paths)
- Scroll to "Function associations"
- Under "Viewer request", select the function you created
- Save changes
- Publish the Function:
- Go back to Functions
- Select your function
- Click "Publish" to associate it with a CloudFront distribution
- Wait for Deployment:
- CloudFront will deploy the changes (usually 5-15 minutes)