Amazon Route 53
Developer Guide (API Version 2013-04-01)

Redirecting Internet Traffic to Another Domain and Redirecting HTTP Requests to HTTPS

You can use a combination of AWS services to redirect internet traffic from one domain (such as example.com) to another domain (such as example.net) and redirect HTTP request to HTTPS. Here's how it works:

  1. A viewer, such as a web browser, submits a request for a domain such as example.com.

  2. Amazon Route 53 routes the request for example.com to an Amazon CloudFront distribution.

  3. Amazon CloudFront forwards the request to an Amazon S3 bucket that you specified as the origin for the distribution. The bucket doesn't contain your content; instead, when you created the bucket, you configured it to redirect requests to another domain name.

  4. Amazon S3 uses HTTPS to return an HTTP 301/302 status code to CloudFront along with the name of the domain that you want to redirect traffic to, such as example.net.

  5. CloudFront returns the redirect to the viewer.

    Because the response from S3 uses HTTPS, CloudFront uses HTTPS to return the response to the viewer. AWS Certificate Manager (ACM) provides the SSL/TLS certificate that encrypts communication between CloudFront and the viewer.

  6. The viewer submits a request for example.net.

  7. The DNS service for example.net routes the request to the applicable resource, such as another S3 bucket or an EC2 instance running a web server.

Estimated cost

  • There's an annual fee to register a domain, ranging from $9 to several hundred dollars, depending on the top-level domain (TLD), such as .com. For more information, see Route 53 Pricing for Domain Registration. This fee is not refundable.

  • When you register a domain, we automatically create a hosted zone that has the same name as the domain. You use the hosted zone to specify where you want Route 53 to route traffic for your domain. The fee for a hosted zone is $0.50 per month.

  • If you're a new AWS customer, you can get started with Amazon S3 for free. If you're an existing AWS customer, charges are based on how much data you store, on the number of requests for your data, and on the amount of data transferred. For more information, see Amazon S3 Pricing.

Step 1: Set up Route 53

If you already have an AWS account, if you know how to access resources using the AWS console, and if you've created an IAM user, you can skip this step. If you haven't performed those steps, see Setting Up Amazon Route 53.

Step 2: Register a Domain

For information about how to register a domain, see Registering a New Domain.

Step 3: Get an SSL/TLS Certificate from ACM

You can ensure that any HTTP requests are converted to HTTPS, so traffic is encrypted between viewers and the resource that you're redirecting traffic to. To do so, you configure S3 to redirect any HTTP requests to HTTPS. To use HTTPS, you need an SSL/TLS certificate.

If you already have an SSL/TLS certificate for the domain that you're redirecting traffic to, you can skip this step.

If you don't have a certificate, perform the following steps in the Getting Started topic in the AWS Certificate Manager User Guide:

  1. Request a certificate.

  2. Validate that you own the domain using either DNS or email.

Step 4: Create an S3 Bucket and Configure It to Redirect Requests to Another Domain Name

In this tutorial, we're using an S3 bucket as the origin for your CloudFront distribution, but the bucket won't contain your content. Instead, we're using the bucket only to redirect requests from one domain name to another.

To create an S3 bucket and configure it to redirect requests to another domain name

  1. Open the Amazon S3 console at https://console.aws.amazon.com/s3/.

  2. Choose Create bucket.

  3. For Bucket name, specify any value you want. The bucket doesn't need to have the same name as the domain that you're redirecting internet traffic for or the domain that you're routing traffic to.

  4. For Region, choose a region that's close to a large portion of your users.

  5. Choose Next.

  6. On the Set properties page of the Create bucket wizard, choose Next.

  7. Choose Next.

  8. Choose Create bucket.

  9. In the list of buckets, choose the name of your new bucket.

  10. Choose the Properties tab.

  11. Choose Static website hosting.

  12. In the Static website hosting box, make note of the Endpoint URL, for example, http://example.com.s3-website-us-west-2.amazonaws.com. You'll need this value when you create or update a CloudFront distribution in the next procedure.

  13. Choose Redirect requests.

  14. For Target bucket or domain, enter the name of the domain (example.com) or subdomain (www.example.com) that you want to redirect requests to.

  15. For Protocol, enter https, all lowercase.

  16. Choose Save.

Step 5: Create or Update a CloudFront Distribution

You can either create a new CloudFront web distribution or update an existing distribution. Perform the applicable procedure:

To create a CloudFront web distribution

  1. Open the CloudFront console at https://console.aws.amazon.com/cloudfront/.

  2. Choose Create Distribution.

  3. On the Select a delivery method for your content page, in the Web section, choose Get Started.

  4. On the Create Distribution page, for Origin Domain Name, enter or paste the Endpoint URL that you got when you created the bucket, for example:

    http://example.com.s3-website-us-west-2.amazonaws.com

    Note

    Don't choose the name of the bucket from the Origin Domain Name list. The format of the bucket name is different, and the redirect won't work if you choose the bucket from the list.

  5. For the other settings in the Origin Settings section, accept the default values.

  6. Under Default Cache Behavior Settings, for Viewer Protocol Policy, choose HTTP and HTTPS.

  7. For the other settings in the Default Cache Behavior Settings section, accept the default values.

  8. In the Distribution Settings section, accept the default values for all settings except the following:

    Alternate domain names (CNAMEs)

    Enter the names of the two domains that you want users to use to access your content, such as example.com and example.net, or www.example.com and example.com.

    SSL Certificate

    Choose Custom SSL Certificate. Then choose the certificate that you got in Step 3: Get an SSL/TLS Certificate from ACM.

  9. Also in the Distribution Settings section, for Custom SSL Client Support, accept the default value of Only Clients that Support Server Name Indication (SNI). If you choose the other option, you have to pay for dedicated IP addresses to serve HTTPS requests. For more information, see Choosing How CloudFront Serves HTTPS Requests in the Amazon CloudFront Developer Guide.

  10. Choose Create Distribution.

  11. On the CloudFront Distributions page, find the distribution that you just created, and wait for the value of the Status column to change from In Progress to Deployed.

To update an existing CloudFront web distribution

  1. Open the CloudFront console at https://console.aws.amazon.com/cloudfront/.

  2. Choose the ID of the distribution that you want to update.

  3. On the General tab, choose Edit.

  4. Update the following values:

    Alternate domain names (CNAMEs)

    Enter the names of the two domains that you want users to use to access your content, such as example.com and example.net, or www.example.com and example.com.

    SSL Certificate

    Choose Custom SSL Certificate. Then choose the certificate that you got in Step 3: Get an SSL/TLS Certificate from ACM.

  5. Also in the Distribution Settings section, for Custom SSL Client Support, accept the default value of Only Clients that Support Server Name Indication (SNI). If you choose the other option, you have to pay for dedicated IP addresses to serve HTTPS requests. For more information, see Choosing How CloudFront Serves HTTPS Requests in the Amazon CloudFront Developer Guide.

  6. Choose the Origins tab.

  7. Choose Create Origin.

  8. For Origin Domain Name, enter or paste the Endpoint URL that you got when you created the bucket, for example:

    http://example.com.s3-website-us-west-2.amazonaws.com

    Note

    Don't choose the name of the bucket from the Origin Domain Name list. The format of the bucket name is different, and the redirect won't work if you choose the bucket from the list.

  9. Choose Create.

  10. Choose the Behaviors tab.

  11. Choose the cache behavior that has Default (*) in the Path Pattern column, and choose Edit.

  12. In the Origin list, choose the origin that you created in steps 7 and 8.

  13. Change Viewer Protocol Policy to HTTP and HTTPS.

  14. Choose Yes, Edit.

  15. In the navigation pane, choose Distributions.

  16. Find the distribution that you just updated, and wait for the value of the Status column to change from In Progress to Deployed.

Step 6: Create a Route 53 Record that Routes Traffic to Your CloudFront Distribution

The final step before you can test the configuration is to add a record to Route 53 that routes traffic to your CloudFront distribution. Perform the following procedure.

To create a Route 53 record that routes traffic to your CloudFront distribution

  1. Open the Route 53 console at https://console.aws.amazon.com/route53/.

  2. In the navigation pane, choose Hosted zones.

  3. Choose the hosted zone that has the same name as the domain that you're redirecting traffic for.

  4. Choose Create Record Set.

  5. Specify the following values:

    Name

    Specify the domain or subdomain name that you want to redirect internet traffic for. The default value is the name of the domain.

    If you want to redirect traffic for a subdomain, enter the value that precedes the domain name. For example, to redirect traffic for www.example.com, enter www.

    Type

    Accept the default value, A – IPv4 address.

    Alias

    Choose Yes.

    Alias Target

    In the CloudFront distributions section of the list, choose the distribution that you created or updated in Step 5: Create or Update a CloudFront Distribution. The list of distributions includes an alternate domain name.

    Note

    If you use one AWS account to create the current hosted zone and a different account to create a distribution, the distribution won't appear in the Alias Targets list. Enter the CloudFront domain name for the distribution, such as d111111abcdef8.cloudfront.net.

    Routing Policy

    Accept the default value of Simple.

    Evaluate Target Health

    Accept the default value of No.

  6. Choose Create.

Step 7: Test the Configuration

To verify that the website is working correctly, open a web browser and browse to the following URLs. In both cases, you should see the content for the domain that you're redirecting DNS queries to:

  • http://domain-name-that-you're-redirecting-from

  • https://domain-name-that-you're-redirecting-from

In some cases, you might need to clear the cache to see the expected behavior.