Image of Change your domain and preserve SEO with AWS Route 53, AWS S3, and AWS Cloudfront

ADVERTISEMENT

Introduction

Oftentimes, a company or website decides to rebrand or transition to a new domain name.

When I first created this website, I purchased the domain initialcommit.io since it was available while the .com TLD (top-level domain) was taken. A few years later, I noticed that the initialcommit.com domain came on the market for a fair price, so I snapped it up.

I was slightly nervous because I had spent countless hours building up the SEO for initialcommit.io. Luckily with the right steps, it is possible to make the change to a new domain as seamless as possible for your users, while preserving SEO in the process.

In this article, we'll discuss changing a website's domain while preserving SEO using several Amazon Web Services including AWS Route 53, AWS S3, and AWS Cloudfront.

The Importance of 301 Redirects

The most important step in preserving SEO through a domain change is to properly redirect your old links that are spread across the Internet. If done incorrectly, you could end up with a bunch of broken links that negatively impact your rankings and traffic.

The goal is that each of your existing links out there on the web should seamlessly redirect to the same page on your new domain. This can be achieved using 301 redirects. This type of redirect has an HTTP Status Code of 301 Moved Permanently. It is intended to be used when a resource has permanently moved to a new location.

We will see how to use AWS S3 (Simple Storage Service) to set up 301 redirects from the old domain to the new domain.

Configure AWS Route 53 Nameservers

But first, we'll discuss another AWS service called Route 53. Route 53 is a DNS service hosted by AWS. Using Route 53's nameservers for our domain will allow us to take advantage of other AWS services like S3, Cloudfront, and Certificate Manager to accomplish a variety of tasks.

By default, you probably use the nameservers provided by the company you bought your domain from, such as Namecheap.com or GoDaddy.com. Switching to Route 53's nameservers allows definition of DNS entries directly in the AWS console instead.

Follow these steps to create a new Hosted zone for your old site in AWS Route 53:

  1. Log into AWS and browse to the Route 53 service.
  2. Click on the link for Hosted zones and click the Create hosted zone button.
  3. Type your old domain name into the Domain name field.
  4. Leave the default Public hosted zone radio button enabled and click the Create hosted zone button.
  5. Now that your hosted zone is created, you should see a list of 4 Name servers in the Hosted zone details.
  6. Now is the time to update your current DNS service (such as Namecheap.com or GoDaddy.com) to use these Route 53 name server URLs instead of the default or existing ones. This varies depending on the company you are using. Usually after you log into your DNS hosting account there is a Manage DNS option which will show you the active name servers and allow you to change them. If not you can call them to ask how to do this.
  7. You will probably want to recreate any DNS records existing in your old DNS provider in AWS Route 53.
  8. It may take 30 minutes to a few hours for your DNS changes to propagate and take effect.

Now that you are using AWS Route 53 to host the DNS for your old domain, you probably want to follow steps (1) - (8) again to add a hosted zone for your new domain as well.

Set up AWS S3 static site redirect

AWS S3 (Simply Storage Service) primarily allows you to create buckets for storing files in the cloud. But it has a few lesser-known functionalities such as the ability to host static websites and even to receive incoming web requests to a domain or service and redirect them somewhere else. We can pass requests to our old domain into the S3 bucket which will redirect them to the same path, with the same cookies and query string parameters, to our new domain.

Now you're ready to create an S3 bucket to perform your redirects:

  1. Log into AWS and browse to the S3 service.
  2. Click the + Create bucket button.
  3. Enter your bucket name and click Create in the bottom left. Note that it's fine to leave "Block all public access" enabled by default.
  4. Back in the S3 list, click the new bucket's name and then click the Properties tab.
  5. Click the Static website hosting block to expand its options.
  6. Enable the second radio button Redirect requests.
  7. Type your new domain into the "Target bucket or domain" field and https into the "protocol" field.
  8. Before saving, make sure to copy our the Endpoint URL at the top of the block. It should look like http://your-bucket-name.s3-website-us-west-2.amazonaws.com
  9. Click save.

Your S3 bucket configuration is complete! Let's move on the AWS Cloudfront setup, which is required for forwarding HTTPS requests from the old domain to the new one.

Set Up AWS Cloudfront Distribution with HTTPS and Point to S3 Bucket

AWS Cloudfront is a content delivery network (CDN) that can be used to efficiently distribute content around the world. We can use it to implement HTTPS as a part of our redirect process, since S3 doesn't support configuration of HTTPS certificates. For that reason we can set up a Cloudfront distribution and configure it with HTTPS, which will then forward our requests to the S3 bucket created in the previous section.

If you need to redirect over HTTPS, follow these steps to set up an AWS Cloudfront distribution to point to the S3 bucket created in the last step:

  1. Log into AWS and browse to the Cloudfront service.
  2. Click the Create Distribution button.
  3. Click Get Started under the "Web" delivery method section.
  4. In the Origin Domain Name field, paste the endpoint URL from step (8) in the previous section.
  5. Leave the Origin Path blank and enter your domain in the Origin ID field.
  6. Scroll down and for Viewer Protocol Policy choose Redirect HTTP to HTTPS.
  7. For Allowed HTTP Methods choose GET, HEAD, OPTIONS, PUT, POST, PATCH, DELETE.
  8. For Cache and origin request settings choose Use legacy cache settings.
  9. For Forward Cookies select All.
  10. For Query String Forwarding and Caching choose Forward all, cache based on all.
  11. For Alternate Domain Names (CNAMEs) enter your domain name with and without the www. subdomain.
  12. For SSL Certificate choose Custom SSL Certificate (example.com).
  13. Click on the empty field to select the SSL certificate for your old domain, or click Request or Import a Certificate with ACM to import your old domain cert into AWS.
  14. Scroll down to the bottom and click the Create Distribution button in the bottom right.
  15. Cloudfront should now show you the Domain name for your new distribution - it will look like xxxxx.cloudfront.net. If not you can find it on the "Cloudfront Distributions" screen. Copy and paste this to keep it handy.

Now we need to create a new DNS entry in AWS Route 53 which will reroute requests to the old domain to the new Cloudfront distribution.

Create DNS Entry in AWS Route 53 to Cloudfront distribution

The final task is creating two new DNS records to reroute requests from your old domain into the new Cloudfront distribution. This is required so that users who attempt to access your old domain will be forwarded to the Cloudfront distribution, which will enforce the HTTPS security and then forward the request to our S3 bucket, which will then redirect to our new domain! It sounds a bit complex, but it works great in my experience!

  1. Log into AWS and browse to the Route 53 service.
  2. Click on the Hosted Zone for your old domain.
  3. Click the Create Record button, choose Simple routing, and click the Next button.
  4. Click Define Simple Record, and leave the Record name field empty.
  5. In the Value/Route traffic to field, choose Alias to CloudFront distribution.
  6. Choose the region of your distribution and select your distribution from the list. If it doesn't show up, you should be able to copy/paste the Domain name from step (15) in the previous section.
  7. For the Record type, choose A - Routes traffic to an IPv4 address and some AWS resources.
  8. Click the Define simple record button to save your entry.
  9. We will define one more DNS record, so repeat step (3).
  10. Click Define Simple Record, and for the Record name field type www.
  11. Repeat steps (5) and (6).
  12. For the Record type, choose CNAME - Routes traffic to another domain name and some AWS resources.
  13. Click the Define simple record button to save your entry.

Note: Sometimes the new interface for Route 53 can be a bit buggy and frustrating, by greying-out certain fields and not letting you choose the values you need. It may be easier to select the option to use the old Route 53 interface instead.

That's it! All of our routing and redirecting should be done! It may take around 30 minutes for your DNS changes to propagate and take effect. After that you should be able to browse to any of your old domain URL's and automatically be redirected to the same page on your new domain!

Move Site in Google Search Console

Alright - it's time for the moment of truth - telling Google about our domain change. Before doing this, it's wise to test several redirects from your old domain to your new one:

  • Test redirects by typing links to your old domain directly in a browser URL bar.
  • Test this for as many pages as you can, with and without the www. subdomain.
  • Re-test all scenarios while explicitly typing http:// and https:// to make sure all forms work and properly redirect to secured https:// pages.
  • Test opening some of your links from the Google SERP results and make sure the redirects work properly.
  • Test opening some of your links from your existing linking domains and make sure the redirects work properly.

Once you are confident that all your redirects and HTTPS are working smoothly...

  1. Log into Google Search Console.
  2. Scroll down and click Settings in the left sidebar.
  3. Click Change of Address.
  4. Follow the simple steps to enter your new domain and confirm the move.
  5. You may need to verify the new domain with Google by adding a TXT DNS record into Route 53.

Congratulations! Google will now go through the slow and steady process of moving your domain. Note that this process can take weeks or months to complete. Just be patient. Slowly over time you'll notice your Google search results will start showing the new domain. Google will preserve your hard-earned SEO in the process.

Contact Your Best Linking Domains to Repoint Links to New Domain

It is a good idea to contact your highest quality linking domains and ask them to update your do-follow links to use your new domain. In my experience, this is a quick and easy task that other site admins are happy to help out with, so don't be shy!

No Change Required in Google Analytics or Google Tag Manager

Luckily, none of the Google Analytics or Google Tag Manager embedded scripts directly reference your domain. As long as you leave those snippets alone, they should work just fine after you set up your redirects.

Create and Verify New Site in Google AdSense (Optional)

However, we do need to tell Google AdSense about the new domain:

  1. Log into Google AdSense and click on Sites in the left sidebar.
  2. Click the Add site button in the top right.
  3. Enter the URL of your new site.
  4. Ensure any code snippets and the /ads.txt file are already included in your site (it should just re-use the same snippets), or add them to your site if not present.

It may take a few days for Google AdSense to verify your new domain and start serving/monetizing ads.

Conclusion

In this article, we explained how to change a website's domain while preserving SEO. We accomplished this using AWS Route 53, AWS S3, and AWS Cloudfront.

If you're interested in learning more about Amazon Web Services, check out The Most Complete Guide to Amazon Web Services from Beginner to Advanced Level.