I have an AWS S3 bucket set up as a web site. It is using Route 53 for DNS and using AWS Certificate Manager for SSL certificates. The public site is a CloudFront distribution of the S3 website bucket using HTTPS. The distribution is set up to redirect HTTP to HTTPS. This entire AWS configuration is set up programmatically using the AWS Java SDK v2 (although this is not relevant to the issue, as I can verify all this manually via the AWS web console).
I have tried two types of redirects from foo.html
to bar.html
, both successful:
- Redirect using routing rules with
<ReplaceKeyWith>bar.html</ReplaceKeyWith>
, making sure to add a<HostName>
(see more discussion on another Stack Overflow question). - Redirect using redirect S3 objects, with the redirect location set to
/bar.html
(because object redirects apparently require absolute paths).
Everything works fine except for one oddity: regardless of which redirect approach I use, when I redirect from foo.html
to bar.html
, even starting at an HTTPS URL, CloudFront will initially return an insecure HTTP-based indirect URL, which then redirects to the HTTPS URL, like this:
https://example.com/foo.html
redirects tohttp://example.com/bar.html
redirects tohttps://example.com/bar.html
This occurs for both routing-rule redirects and S3 object redirects. I tested this using the network developer tools in both Chrome and Firefox on Windows 10.
Why is CloudFront providing the intermediate HTTP redirect? As my initial URL is using HTTPS, why doesn't it directly redirect to the HTTPS form?