I am hosting a static site on aws via s3/coludfront. Anyway I can force cloudfront to redirect all http request to https version.
Asked
Active
Viewed 4,124 times
2 Answers
16
To force http -> https.
- Go to the cloudfront distribution
- Select the distribution
- Go to behaviour
- select the one and click edit
- Now you have a option of redirecting http -> https

aWebDeveloper
- 36,687
- 39
- 170
- 242
-
1See https://stackoverflow.com/a/46481196/5473824 for how this is done in cloudformation . – Adrian Baker Jul 26 '18 at 22:47
5
If you're using CloudFormation:
Resources:
Distribution:
Type: AWS::CloudFront::Distribution
Properties:
...
DistributionConfig:
DefaultCacheBehavior:
ViewerProtocolPolicy: redirect-to-https
...
Previous answer said to use https-only but that will return a 403 (Forbidden) if the viewer sends an HTTP request.
https://docs.aws.amazon.com/cloudfront/latest/APIReference/API_CacheBehavior.html

Community
- 1
- 1

Andrew Allison
- 1,122
- 2
- 13
- 30