Search code examples
http-redirectamazon-s3amazon-cloudfront

cloudfront and s3 301 redirect shows naked domain of the bucket


I have a static web site on an s3 bucket. the domain address is example.com and works fine.

Now I want to route all traffic to www.example to the same bucket with a 301 redirect.

For this I have done the following:

  1. I have set up a bucket, that directs all traffic to the other bucket (I entered the full endpoint url with example.com.s3-website.eu-central-1.awsamazon.com)

  2. I have set up a cloudfront distribution for www.example.com, which has the bucket for the www.example.com (which only redirects all traffic to the bucket of example.com). I have entered the alternate domain name as www.example.com

  3. I have set up a route 53 entry for www.example.com A record that points to cloudfront distribution of www.example.com.

The problem that I have is, the redirection works fine, but the naked endpoint url is displayed after redirect on the address bar of the browser. I want it to display www.example.com

The actual address is prochoice.com.tr

Thank you in advance for all help.


Solution

  • I have set up a bucket, that directs all traffic to the other bucket (I entered the full endpoint url with example.com.s3-website.eu-central-1.awsamazon.com)

    That's the problem. You want to enter the actual hostname that you want the browser to be told to request -- not the underlying endpoint.

    The value for this would just be example.com.