2

I am using Elastic Beanstalk on AWS for a .net core site hosted on IIS.

I'm unsure how to get http to redirect to https. Following this:

https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/configuring-https-httpredirect.html

I have done the first step, but unsure what to do in the second step. I'v followed the github link, but dont know what to do with the file.

https://github.com/awsdocs/elastic-beanstalk-samples/blob/master/configuration-files/aws-provided/security-configuration/https-redirect/dotnet/https-redirect-load-balanced-dotnet.config

Instructions are unclear.

I'm open to suggestions of other methods of getting http to redirect to https

raklos
  • 28,027
  • 60
  • 183
  • 301
  • use this url rewrite rule in iis: ` ` for more detailed information refer this link: [link1](https://aws.amazon.com/premiumsupport/knowledge-center/redirect-http-https-elb/) ,[link2](https://stackoverflow.com/questions/19791820/redirect-to-https-through-url-rewrite-in-iis-within-elastic-beanstalks-load-bal) – Jalpa Panchal Oct 14 '19 at 06:27

2 Answers2

5

I was confused by all the documentation and answers providing code for rewrite rules, which I could never get to work. I eventually figured out how to do this via the AWS web console:

  1. Make sure you are using an Application Load Balancer for your application's environment.

  2. Add a listener for https, port 443, and your certificate (AWS documentation covers this quite well)

  3. This was the part that took me hours to figure out:
    You cannot configure the redirect from Elastic Beanstalk's load balancer configuration section. You have to go to Services -> EC2 -> Load balancers and then select the load balancer created for your application/environment.
    If you have multiple load balancers, it's hard to determine which one is the correct one. I had to refer to the "Created At" timestamp to know which one to select.

  4. Click the "Listeners" tab

  5. Click the View/edit rules link on the HTTP:80 listener
  6. Click the + icon to add a new rule
  7. Add an action of "Redirect to..." and enter 443 for the port.
    The rest of the inputs defaulted to the correct values.
  8. Add a "Host header" condition and set the value to your host
  9. Save the rule
Mike Gostomski
  • 138
  • 2
  • 8
  • 2
    This should be the answer for all the questions related to HTTPS redirection on Elastic Beanstalk! Thanks Mike! – joe kirk Sep 27 '21 at 15:42
  • This has taken me hours! Thank you so much. Is it also necessary to set a host value for both www.domain.com and domain.com (no www)? Or just one of them? – Cameron Ward Dec 21 '21 at 17:31
0

This is what worked for me https://stackoverflow.com/a/47806650/66975

<rewrite>
   <rules>
      <rule name="HTTPS Rule behind AWS Elastic Load Balancer Rule" stopProcessing="true">
         <match url="^(.*)$" ignoreCase="false" />
         <conditions>
            <add input="{HTTP_X_FORWARDED_PROTO}" pattern="^http$" ignoreCase="false" />
         </conditions>
         <action type="Redirect" url="https://{SERVER_NAME}{URL}" redirectType="Found" />
      </rule>
   </rules>
</rewrite>
raklos
  • 28,027
  • 60
  • 183
  • 301