This is a mini writeup for a very specific case.
Let’s say we have a domain name,
ourcooldoma.in. And for some reason we want to redirect all traffic to
somecool.org. And the following things also apply:
ourcooldoma.inis registered at a hoster like Namecheap.
somecool.orgdoes not belong ot us at all.
- we want to redirect
- we are already using
(Told you it was specific..)
Then we can do this:
- Set up an empty S3 bucket at AWS and make it public.
- In the properties of the bucket use the Static Website Hosting feature in Properties and define a redirect to
somecool.org. Take note of the Endpoint value in the Static Website Hosting box.
- Because we support HTTPS use
ACMto create a certificate that matches
- Create a Cloudfront distribution that uses that bucket’s Endpoint as origin and is valid for the domains
ourcooldoma.in. Use the certificate from the step before.
ALIASrecords at Namecheap for
@pointing to the domain name of our Cloudfront distribution.
Now every request to
ourcooldoma.in will result in a DNS query that returns the
ALIAS entry (though I believe
ALIAS is not a standard key but a technicality provided by Namecheap and others to circumvent the restriction of
CNAME, which one would normally use, but which cannot be used with
@ unless you are ok with masking your
MX and other subdomain records).
So our request will be actually fired against the IP address at Cloudfront but the client still expects a valid SSL certificate for
ourcooldoma.in. Cloudfront provides that (created in step 3) and we can finally get to the (cached) bucket, which only does one thing:
301 redirect the client to
P.S.: You can follow me on Twitter.