How do I redirect a domain in CloudFront?

2 minute read
0

I want to redirect my domain to another domain in Amazon CloudFront. How can I do this?

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 theRedirect 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 Choosing between CloudFront Functions and Lambda@Edge.

For Lambda@Edge:

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

For CloudFront Functions:

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


Related information

Configuring a webpage redirect

Creating a Lambda@Edge function in the Lambda console

Tutorial: Creating a simple function with CloudFront Functions

AWS OFFICIAL
AWS OFFICIALUpdated 2 years ago