AWS Route 53 – Web Redirect

When you have a website URL that is lengthy and difficult to remember, the first thing you may think of is to bookmark it. However, after you bookmarked so many of them, hunting for a website among a large list of bookmarks is still a pain. There is another way. You can set up a short and easy-to-remember domain name to redirect to the web URL.

Web Redirect vs CNAME

Before we start the hands-on, let’s have a quick look at the differences between Web Redirect and CNAME.

How CNAME works is like pointing two domain names to the same web server. For example, assume you’ve already mapped domainA.com to your web server’s IP address. If you also want to point domainB.com to the same website server, you can set domainB.com’s CNAME to be domainA.com. As a result, by opening either domain names in your browser, you will see the same website.

There is a limitation with the CNAME though. If you want to point domainB.com to a particular directory of domainA.com, e.g. http://domainA.com/directoryA/pageA.html, CNAME can’t do it. This is where the web redirect can help.

How web redirect works is like you come to website A, it tells you “sorry mate, I’ve moved. This is the new address – website B”. We can see that the web redirect is achieved via a middle-man website instead of DNS settings. So you almost need two websites, one redirects to another. In AWS’s context, using just Route 53 is not enough. And we don’t want to spin up an EC2 just to do the redirect job. Luckily, we have Static Website Hosting from S3 as a cost-effective option. The diagram below demonstrates how it works.

web redirect

The static website configured in S3 is acting as the middle man. The Route 53’s job is to direct all access traffic to the middle man. The middle man then redirects the traffic to the final destination. We’ll show you how to do this web redirect using AWS Route 53 + S3 below.

Hands-On

The hands-on case we’ll demonstrate is to redirect domainB.com to http://domainA.com/directoryA/pageA.html. To set up this web redirect, there are a few prerequisites:

  • you have sufficient permission to configure Route 53 and S3 in an AWS account
  • you’ve delegated DNS management of domainB.com to Route 53 in this account*

* You can achieve the DNS Delegation by either registering the domainB.com directly in AWS Route 53, or point this domain’s NS records to AWS name servers. We’ll show you how to delegate a domain name’s DNS management in a separate article.

Once you have the prerequisites met, you can follow the steps below to configure the web redirect.

Set up S3 bucket

  1. Log in to the console of your AWS account, and navigate to the S3 console page
  2. Click the Create Bucket button to bring up the Create Bucket wizard page
  3. Enter the redirect-from domain name in the Bucket name field, in our case, domainB.com
  4. Choose the AWS Region that suits your geolocation, keep the rest settings as default, and then click the Create bucket button at the bottom of the page.
  5. Once the bucket is created, click the bucket name from the bucket list, and then click the Properties tab.
  6. On the Properties page, click the Edit button in the Static website hosting panel.
  7. Select the Enable radio button, and then select Redirect requests for an object
  8. In the Host name field, enter the redirect-to URL, in our case, domainA.com/directoryA/pageA.html
    Note, don’t put http:// or https:// in front of the URL. The protocol should be specified at step 9 below.
  9. The Protocol setting is optional, e.g. if you want to route all traffic on to an SSL connection, you can choose https.
  10. Click the Save changes button.

    Now you should see a Bucket website endpoint displayed in the Static website hosting panel. In our case, it’s http://domainB.com.s3-website-ap-sourtheast-2.amazoneaws.com. We need to note down the part that’s highlighted in red. It’ll be required in Route 53 configuration.

Set up Route 53

  1. Navigate to the Route 53 console page, and then click the redirect-from domain name from the list, in our case domainB.com.
  2. On the hosted zone details page, click the Create record button.
  3. On the Quick create record page, select A-Routes traffic to an IPv4 address and some AWS resources in the Record type field.
  4. Switch on the Ailias button, and then select Alias to S3 website endpoint in the Route traffic to field.
  5. Select the same region as you configured in your S3 bucket (ref step 4 in S3 bucket configuration)
  6. Paste the endpoint that you’ve noted down at the end of S3 bucket configuration
  7. Select Simple routing in the Routing Policy field, and set No for Evaluate target health.
  8. Click the Create records button.

Usually AWS Route 53 will propagate DNS records changes to its world-wide DNS servers within 60 seconds. If you Once it’s ready, your web redirect from domainB.com to http://domainA.com/directoryA/pageA.html will start to take effect. From now on, you can just use the branded domain name to access your mapped web page. You can still use the orginal lengthy URL to access the same page, but why bother?

For more information about AWS S3 static web hosting, see Hosting a static website using Amazon S3.

You May Also Like

About the Author: Richard Zhao

My name is Richard Zhao. I'm a solution architect and owner of cloudstudio.com.au. Having built knowledge bases for many companies, I'd like to use this cloud studio to share knowledge and ideas with wider people on the internet.

8 Comments

  1. Currently it sounds like BlogEngine is the best blogging platform out
    there right now. (from what I’ve read) Is that what you’re using on your blog?

  2. hello there and thank you for your info – I have certainly
    picked up anything new from right here. I did however expertise a few technical issues using this site, since I experienced
    to reload the site a lot of times previous to I could get
    it to load correctly. I had been wondering if your web
    hosting is OK? Not that I am complaining, but sluggish loading instances times will sometimes affect your placement in google and could damage your high quality score if ads and marketing with Adwords.
    Anyway I’m adding this RSS to my e-mail and can look
    out for a lot more of your respective exciting content.

    Ensure that you update this again soon.

    1. Thanks for the feedback Priscilla. I’ve tried to load the site on different browsers. The site loads ok. Please let me know if you still see the same loading issue.

  3. I am curious to find out what blog platform you’re using?

    I’m having some small security problems with my latest blog and I would like
    to find something more safeguarded. Do you have any solutions?

    1. hi Meagan, I’m using WordPress for my blog. The security posture can be boiled down to multiple tiers, like application tier, OS tier and infrastructure tier. The second and third ones are usually taken cared by the service provider. So choosing a good service provider will lift the bar there. For the first one, the application tier, a few areas you may enhance, e.g. using complex passwords, change it regularly, install security plugin to assess the existing security gaps, etc. And doing regular backups is always a good-to-have habit. If we are prepared in both proactive and reactive aspects, the chance if having security issue will be reduced. Hope it helps.

Leave a Reply

Your email address will not be published. Required fields are marked *