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
ourcooldoma.inandwww.ourcooldoma.in. - we are already using
AWS.
(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 matchesourcooldoma.inandwww.ourcooldoma.in(or*.ourcooldoma.in). - Create a Cloudfront distribution that uses that bucket’s Endpoint as origin and is valid for the domains
www.ourcooldoma.inandourcooldoma.in. Use the certificate from the step before. - Configure
ALIASrecords at Namecheap forwwwand@pointing to the domain name of our Cloudfront distribution.
Done!
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 somecool.org.
P.S.: You can follow me on Twitter.
Lukas Z's Blog