Rohan
Rohan

Reputation: 456

Heroku redirect from example.com to www.example.com retaining HTTPS using AWS

I have a Heroku app set up with SSL certificates, and my DNS does not allow CNAME records at the Apex level. Meaning, I cannot point my A Record at my Heroku app URL (A level records can only be IP addresses and Heroku cannot provide a static IP).

There other methods (both here on stack and on heroku's guides) that recommend using other DNS providers, but I would like to try and solve this with AWS (Specifically Route53), while also retaining our https:// in the domain for SSL.

I found some guides on how to do this, but there seemed to be complications (headers messed up, cannot retain https etc). I will provide an answer below outlining how I achieved this, but encourage discussion on what repercussions my solution may incur.

Upvotes: 3

Views: 706

Answers (1)

Rohan
Rohan

Reputation: 456

I discovered this guide on the Heroku website: Configuring Amazon Route 53 DNS for Your Heroku App

The outline of the solution is to create an S3 bucket as a static website host that simply redirects to your Route53 hosted zone. Here are the basic steps:

  1. Create a new hosted zone on your Route 53 Management Console with your domain (example.com)
  2. Create a CNAME entry for www.example.com with the value set as your heroku custom domain (www.example.com.herokudns.com)
  3. Create an S3 Bucket with the same name as your domain (example.com), and set it as a static website host
  4. In the settings for static website hosting set this to "Redirect Requests" and set the target as www.example.com and the protocol to https Settings for s3 bucket static website hosting
  5. Return to Route 53 and add an A Level Alias with the target as your newly created bucket
  6. Finally point your DN Providers Name servers at your new Route 53 hosted zone (you can get the list of name servers from the sidepanel in your management console)

And that's it! After the TTL expires on your Name Servers your site should be up and running and both example.com and www.example.com

Upvotes: 1

Related Questions