Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force cloudfront to use https (redirect http -> https)

I am hosting a static site on aws via s3/coludfront. Anyway I can force cloudfront to redirect all http request to https version.

like image 551
aWebDeveloper Avatar asked Feb 19 '17 08:02

aWebDeveloper


1 Answers

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

like image 108
Andrew Allison Avatar answered Sep 19 '22 16:09

Andrew Allison