2

I'm hosting a static website on AWS and want the naked domain to redirect to www. For example, if the user enters example.com I want it to show as www.example.com.

I found this question which is the exact same question as mine, but I want to ask a few more specifics before I take my site offline to change this.

I followed the AWS tutorial to deploy a static website. So if I want my root bucket to redirect to the www bucket, I will deploy the HTML/CSS/JS files to the www bucket and then set the root bucket to redirect?

Lastly, when I set the bucket policy. This is how the tutorial explained to do it for the root domain:

{
  "Version":"2012-10-17",
  "Statement": [{
    "Sid": "Allow Public Access to All Objects",
    "Effect": "Allow",
    "Principal": "*",
    "Action": "s3:GetObject",
    "Resource": "arn:aws:s3:::example.com/*"
  }
 ]
}

I wouldn't need this anymore and instead would put this on the www bucket. However, do I change the Resource to www.example.com/*?

{
  "Version":"2012-10-17",
  "Statement": [{
    "Sid": "Allow Public Access to All Objects",
    "Effect": "Allow",
    "Principal": "*",
    "Action": "s3:GetObject",
    "Resource": "arn:aws:s3:::www.example.com/*"
  }
 ]
}

So it would be

"Resource": "arn:aws:s3:::www.example.com/*"

Is that how you would set it up?

2

Create your www.example.com bucket and set it up for hosting a static website. Apply your policy (pasted here for completion):

{
  "Version":"2012-10-17",
  "Statement": [{
    "Sid": "Allow Public Access to All Objects",
    "Effect": "Allow",
    "Principal": "*",
    "Action": "s3:GetObject",
    "Resource": "arn:aws:s3:::www.example.com/*"
  }
 ]
}

The Resource property is updated with the current bucket.

Once that's in place, deploy your website to this bucket. Update your Route 53 records to point www.example.com to this bucket. You should then test www.example.com to ensure it's working. If not, fix it. Only when it's working should you continue.

Once the www.example.com is working, then you would modify your example.com bucket to simply redirect to www.example.com. No need to modify your Route 53 records since it's already pointing to your example.com bucket.

Once this is done, your browser should hit example.com and then be redirected to www.example.com.

When you're all done, you can delete all the objects from your example.com bucket since they're not being accessed anymore. You can also remove any custom permissions/policies on that bucket.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.