How to Redirect or Forward HTTPs From One Domain to Another Without Certificate Errors
By Bobby Gill on August 12, 2021
If you have a domain and would like to forward it to another, most domain providers make this rather trivial to do for HTTP calls. For instance, in GoDaddy you can setup Domain Forwarding and it will take care of this for you either by issuing a HTTP redirect or by masking your domain with the domain you want to forward to. However, while this makes redirecting a HTTP call to a relatively simple, where it often falls apart is when you want to redirect HTTPS from ‘domain1.com’ to ‘domain2.com’. If you use GoDaddy’s domain forwarding, attempting to access https://domain1.com in your browser will result in this certificate error:
In this article, I will show you how to solve this issue quickly and without the use of any intermediate servers or any mucking about in .htaccess files, all through the use of Amazon Web Services.
At a high level, we will redirect both HTTP and HTTPs for domain1.com to domain2.com by leveraging a AWS’s Application Load Balancer (ALB) , a certificate provisioned by AWS and a redirect rule setup on the Application Load Balancer.
Pros to this approach:
You don’t need to pay for a SSL certificate for domain1.com
You do not need to spin up a server and and use a .htaccess file at the Apache or NGINX level to perform the redirect.
You avoid any SEO issues by implementing a permanent HTTP redirect of domain1.com to domain2.com
Cons to this approach:
While you save the cost of the certificate, you will pay for the cost of the ALB, which is at least $15 /month. Note, if you already have a ALB setup for a different purpose you can re-purpose that existing ALB to implement this solution!
Throughout this example I will refer to domain1.com as the domain we are looking to redirect and domain2.com as the target of that redirection.
1.) An AWS account.
2.) Access to the DNS settings for domain1.com.
Steps to Setting Up a HTTPS Redirect From Domain1.com to Domain2.com
1.) Provision a Certificate for Domain1 in AWS Certificate Manager
Provision a public certificate, for the domain name enter “domain1.com”, and optionally, “*.domain1.com” so you can use this certificate for all subdomains as well.
Choose to use DNS validation, you will be displayed two DNS CNAME values to copy to the DNS of domain1.com. Both of them are the same, so you only really need to add 1 of them. The CNAME record it instructs you to add will look like:
Name: <random alphanumeric>.domain1.com
Value: <random alphanumeric>.<random alphanumeric>.acm-validation.aws. (note you need to make sure you add the trailing period to the value!)
Login to your DNS provider, add the CNAME record from the previous step to your domain1.com DNS entries.
Return to the Certificate Manager console, click the refresh button. After a minute or two, you should see the certificate status change to “Issued”. Do not proceed to the next step until you see “Issued”.
2.) Create Application Load Balancer in AWS EC2 Console