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 301 redirect a site with AWS S3 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.

For a bit of added confusion, S3 can do 301 redirects but it cannot add SSL (HTTPS) on its own, so you need to use Cloudfront as well.

The Basic 301 Layout

If you already know your way around AWS, here is what we are going to to do.

  1. Route 53 DNS with A name for domain and www. using the Cloudfront distribution
  2. Cloudfront distribution pointing to the S3 website endpoint
  3. S3 bucket for the domain and www. domain
  4. Both S3 buckets are set to Redirect All Requests in the “Static Website Hosting” settings
  5. Leave the “https or http” section blank

That’s it!

How To Do The Redirect

Here at the full, start from fresh, instructions for 301ing a S3 domain. First, do the AWS S3 work:

  1. Create an S3 bucket that is named after your site, say
  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,

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. (You can pick a Cloudfront distribution if you have one, see below) Choose the right one. 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 “”.

Note: Endpoints will not appear immediately after they are created. They can take up to 15 minutes to show up!

For HTTPS Add In Cloudfront

While the above method should work find for you, I actually prefer adding Cloudfront into the mix. This is mandatory if you want HTTPS URLs. The good news is that this is cheap and pretty simple:

  • Route 53 points to Cloudfront instead of your S3 website endpoint
  • Cloudfront uses the origin domain name of “ (your S3 website endpoint!)
  • Cloudfront can handle some behaviors and logic, plus it can handle HTTP and HTTPS, avoiding all possible issues. Cloudfront also works with rules that handle everything under a domain (*), can specific a Default Root Object (like index.html), etc.

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.

January 19th, 2020

Posted In: AWS

Tags: , ,

© 2022 | Privacy Policy | About | UTM Creator | CVE Reporting