Cloud Confusing

Explaining hosting, AWS, Wordpress, static sites, and all manner of cloud solutions.

Properly redirecting is something that is easy to say (or request in a ticket) but not always easy to do. It just so happens that its really important for proper site behavior, particularly if you are concerned with SEO.

Here’s how you redirect a site with AWS in the simplest manner possible.

What Kind Of Redirect?

In this case things are pretty simple: you want either a 301 or a 302. A 301 is a permanent redirect, and a 302 is a temporary one. Of course, it’s your server so you can set a 301 redirection and then change it in the future, but the point is that you are signalling to others that the redirection is permanent, so they may stop checking the original URL and only catalog the ultimate one if you pick 301.

Part of the confusion here is that 301s can be done in all sorts of ways. They can be done with Apache or and .htaccess file. The confusion is made greater because you can do a redirection, as in not an HTTP 301, but simply redirecting the browser to another page with even more methods. The thing to know is that a 301 is a server response code, something created on the server-side so you can’t, say, use Javascript to do this.

301 Redirects With AWS

If you are redirecting an entire domain you definitely don’t want to keep a server running simply to handle those redirects. That would be expensive and wasteful. But you need a server-side HTTP code to get return to the browser. What’s the solution?

The easiest and most cost-effective way to do this is by combining Route 53 and S3. Route 53 is Amazon’s DNS and registry tool and S3 is the simple online storage tool.

Basically what you want to do is use Route 53 to configure your DNS (technically any registrar could work, but it’s easier with Route 53 because it’ll be pre-configured) and then use S3 to handle the forward. S3 has built-in forwarding which will respond with a 301 response, despite there not actually being a server there that you control). Do to this you will actually be using S3’s website endpoint, so read up on that.

How To Do The Redirect

First you want to do the S3 work:

1. Create an S3 bucket that is named after your site, say WebSite.biz

2. Within the bucket, go to Properties > Static Website Hosting. Pick redirect and type in where you want the traffic to flow. Here’s where’d you type your new site, WebSiteTwo.io

Now in Route 53, you want to point your DNS from the old server to the new S3 bucket.

1. Go to your website and create a hosted zone.

2. Create an A record (IPv4)

3. Select “Yes” for Alias

4. For Alias Target, open the dropdown menu and look for your S3 website endpoint. Choose that. Now save. Don’t worry about Health Policy or anything else that might distract you.

5. Repeat steps 2-4 for your site’s www. record. Just keep in mind that the www. record will not be able to point directly at the website endpoint, unless you create an S3 bucket called “www.WebSiteTwo.io”. So you can create this bucket and forward it, or simply tell Route 53 to to another alias target in your record set, the one you just setup!

Worth The Trouble: Add In Cloudfront

While the above method should work find for you, I actually prefer adding Cloudfront into the mix. This is pretty simple:

  • Route 53 points to Cloudfront
  • Cloudfront uses the origin domain name of “http://WebSite.biz.s3-website-us-east-1.amazonaws.com (your S3 website endpoint!)
  • Cloudfront can handle some behaviors and logic, plus it can handle HTTP and HTTPS, avoiding all possible issues. Cloudfront also handles everything under a domain (Website.biz/*) if you specific a Default Root Object

Wrapping Up

Now make sure you disable your old server so you don’t have to pay for it any more. You’ll also want to remove any caching distributions you might have had active. Those shouldn’t be a problem after the DNS is switched over, but could cause a lot of confusion down the line.

And that’s it! Give it five minutes and then test with a browser (make sure your cache is cleared), curl command, or online curl tool.

November 24th, 2019

Posted In: AWS

Tags: ,


© Cloudconfusing.com 2019 | Privacy Policy | About