Requirement
In all the following requirement the URL should change in the browser
- firstdomain.com should be redirected to https://sub.seconddomain.com
- http://firstdomain.com should be redirected to https://sub.seconddomain.com
- https://firstdomain.com should be redirected to https://sub.seconddomain.com
Documents Referred
https://aws.amazon.com/premiumsupport/knowledge-center/route-53-redirect-to-another-domain/ I am following this approach in this example
Set up DNS based URL forwarding in Amazon Route53 Amazing solution but does not work for the third scenario i.e. https://firstdomain.com
My S3 configuration
- S3 bucket name : firstdomain.com
- Static website hosting is enabled and the following is the configuration
- protocol: https
- redirect request to: sub.seconddomain.com
CloudFront Configuration
- Origin name : firstdomain.com.s3-website.ap-south-1.amazonaws.com
- Viewer protocol policy: redirect HTTP to HTTPS
- Alternate Domain Names: firstdomain.com and seconddomain.com
- ACM certificate : installed with *.firstdomain.com and *.seconddomain.com
- Noted that the cloudfront name is : something.cloudfront.net
Route53 configuration
- Alias A Ipv4 record created with firstdomain.com -> something.cloudfront.net
Whats happening
- firstdomain.com redirected to http://sub.seconddomain.com
- http://firstdomain.com. redirected to http://sub.seconddomain.com
- https://firstdomain.com redirected to http://sub.seconddomain.com
So all my requests are forcibly being moved to http and the certificate is not being loaded.
Following is the curl output
$ cat curloutput.txt| egrep -i "location|server|301"
< HTTP/1.1 301 Moved Permanently
< Server: CloudFront
< Location: https://firstdomain.com/
* Connected to firstdomain.com (someIP) port 443 (#1)
* successfully set certificate verify locations:
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* ALPN, server accepted to use h2
* Server certificate:
* issuer: C=US; O=Amazon; OU=Server CA 1B; CN=Amazon
* Using HTTP2, server supports multi-use
< HTTP/2 301
< location: http://sub.seconddomain.com/
< server: AmazonS3
< x-cache: Hit from cloudfront
* Connected to sub.seconddomain.com (someip) port 80 (#2)
> GET / HTTP/1.1
> Host: sub.seconddomain.com
> User-Agent: curl/7.64.1
> Accept: */*
>
< HTTP/1.1 404 Not Found
< Content-Type: text/plain; charset=utf-8
< X-Content-Type-Options: nosniff
< Date: Thu, 12 Aug 2021 07:47:58 GMT
< Content-Length: 19
<