title: Route 53 redirect https://domain.com to https://www.domain.com
body: <p>We use an <a href="https://stackoverflow.com/a/28978783/3145800">S3 bucket and Route 53 alias record</a> to redirect <code>domain.com</code> to <code>www.domain.com</code> on a DNS level. This works with http, but does not work with https requests.
  There are TXT and MX records for domain.com, so we <a href="https://stackoverflow.com/questions/20215729/rrset-of-type-cname-with-dns-name-foo-com-is-not-permitted-at-apex-in-zone-bar">cannot use a CNAME</a>. The <code>www.domain.com</code> is a CNAME to our Elastic Beanstalk server.
  The <code>domain.com</code> cannot be an A record since the server's IP address is not fixed.
  What works:</p>
  
  <ul>
  <li>curl <a href="http://domain.com" rel="nofollow noreferrer">http://domain.com</a> => 301 redirect to <a href="http://www.domain.com" rel="nofollow noreferrer">http://www.domain.com</a></li>
  <li>curl <a href="http://www.domain.com" rel="nofollow noreferrer">http://www.domain.com</a> => 301 redirect to <a href="https://www.domain.com" rel="nofollow noreferrer">https://www.domain.com</a></li>
  <li>curl <a href="https://www.domain.com" rel="nofollow noreferrer">https://www.domain.com</a> => served by the EB server</li>
  </ul>
  
  <p>What does not work:</p>
  
  <ul>
  <li>curl <a href="https://domain.com" rel="nofollow noreferrer">https://domain.com</a> => curl: (7) Failed connect to domain.com:443; Connection refused</li>
  </ul>
  
  <p>How to redirect <a href="https://domain.com" rel="nofollow noreferrer">https://domain.com</a> to <a href="https://www.domain.com" rel="nofollow noreferrer">https://www.domain.com</a>? Or alternatively what should we do with the TXT and MX records so we can use a CNAME record?</p>