How do I redirect a domain in CloudFront?

2 minute read
0

I want to redirect my domain to another domain in Amazon CloudFront.

Short description

To redirect a domain in CloudFront, use one of the following:

  • An Amazon Simple Storage Service (Amazon S3) website endpoint that returns a 301 status code
  • An edge function that redirects requests to the new domain

An Amazon S3 website endpoint redirection moves the existing URL path to the redirected domain. Edge functions allow you to redirect viewers to other pages based on information in the request, or rewrite all requests from one path to another.

Resolution

Use an Amazon S3 endpoint that returns a 301 status code

Follow the instructions in the Redirect using Route 53 and Amazon S3 section of How can I redirect one domain to another in Route 53?

Use an edge function that redirects requests to the new domain

For more information on the difference between Lambda@Edge and CloudFront functions, see Differences between CloudFront Functions and Lambda@Edge.

For Lambda@Edge:

See Customize at the edge with Lambda@Edge. For example code, see Example: Generating an HTTP redirect (generated response).

For CloudFront Functions: 

See Customize at the edge with CloudFront Functions. For example code, see Redirect the viewer to a new URL.

Related information

Configuring a webpage redirect

Create a Lambda@Edge function in the Lambda console

Tutorial: Create a simple function with CloudFront Functions

AWS OFFICIAL
AWS OFFICIALUpdated 5 months ago