Skip to content

How do I redirect a domain in CloudFront?

2 minute read
0

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

Resolution

Use an Amazon S3 website endpoint to redirect your domain

An Amazon Simple Storage Service (Amazon S3) website endpoint redirection moves the existing URL path to the redirected domain. Use an Amazon S3 website endpoint that returns a 301 status code. For instructions, see (Optional) Configuring a webpage redirect.

Use an edge function to redirect your domain

You can use an edge function to redirect requests to the new domain. Edge functions allow you to redirect viewers to other pages based on information in the request. Or, you can rewrite all requests from one path to another.

For Lambda@Edge, customize at the edge with Lambda@Edge. To see an example on how to generate an HTTP redirect, see Example: Generating an HTTP redirect (generated response).

For CloudFront functions, customize at the edge with CloudFront Functions. To see an example to redirect a new URL in a CloudFront Function, see Redirect to a new URL in a CloudFront Functions viewer request event.

For more information, see Differences between CloudFront Functions and Lambda@Edge.

Related information

Create a Lambda@Edge function

Tutorial: Create a simple function with CloudFront Functions