Contents

Seamless Redirection for Your Website Using S3, CloudFront, and ACM

Seamless Redirection for Your Website Using S3, CloudFront, and ACM

When managing a website, ensuring users are redirected correctly can significantly enhance user experience and SEO. For instance, if you want to redirect traffic from test-12333333344444.com to www.test-12333333344444.com, you can achieve this seamlessly using Amazon S3, CloudFront, and AWS Certificate Manager (ACM). This guide will walk you through the entire process.

Step 1: Create an S3 Bucket

1 -Create an S3 Bucket:

  • Go to the AWS Management Console and navigate to the S3 service. https://github.com/yahyagulshan/linuxnotes/assets/59036269/fed91723-1adc-4896-bd3f-00fd323750a9

  • Create a new bucket named test-12333333344444.com. https://github.com/yahyagulshan/linuxnotes/assets/59036269/44953b8e-45eb-4b82-9b1c-bb123c3db1db

2 -Configure the S3 Bucket:

  • Open the test-12333333344444.com bucket.

  • Go to the Properties tab. https://github.com/yahyagulshan/linuxnotes/assets/59036269/3f19f8f6-ee65-4a57-8e03-8b7172f0f347

  • Scroll down to Static website hosting and click on Edit. https://github.com/yahyagulshan/linuxnotes/assets/59036269/7ec57ebc-e136-40c3-b647-dd17ca5679d4

  • Enable static website hosting and select Redirect requests. https://github.com/yahyagulshan/linuxnotes/assets/59036269/8146f610-b79c-4c55-a6d7-e8ec6b6046e4

  • Enter www.test-12333333344444.com as the hostname and select https as the protocol.

  • Save the changes.

3 -Set Bucket Policy:

  • Navigate to the Permissions tab of your bucket. https://github.com/yahyagulshan/linuxnotes/assets/59036269/8feee755-a921-4cf5-ab77-75b5f1511826

  • Click on Bucket Policy and add the following policy to allow public read access:

    {
       "Version": "2012-10-17",
     "Statement": [
      {
          "Sid": "PublicReadGetObject",
          "Effect": "Allow",
          "Principal": "*",
          "Action": "s3:GetObject",
          "Resource": "arn:aws:s3:::test-12333333344444.com/*"
      }
     ]
    }
    

https://github.com/yahyagulshan/linuxnotes/assets/59036269/4c181f2d-7fa1-4a01-b2da-8982984287d9

  • Save the policy.

Step 2: Obtain an SSL Certificate with ACM

  • Go to the AWS Management Console and navigate to ACM (AWS Certificate Manager).

https://github.com/yahyagulshan/linuxnotes/assets/59036269/8825ec14-cacc-48b4-8d3a-f4d2a53ba16e

  • Click on Request a certificate.

  • Select Request a public certificate and click Next.

https://github.com/yahyagulshan/linuxnotes/assets/59036269/9c551be9-01be-4792-9227-c68c95968d5b

  • Enter your domain name, test-12333333344444.com, and click Next.

https://github.com/yahyagulshan/linuxnotes/assets/59036269/7aaa2e64-7598-446a-bc60-ccf577448c5b

  • Choose DNS validation and click Next.

  • Review the options and click Request.

2 -Validate the Certificate:

  • Copy the CNAME name and value provided by ACM.

  • Add these CNAME records to your domain registrar’s DNS settings.

  • Wait for ACM to validate the certificate.

Step 3: Configure CloudFront

1 -Create a CloudFront Distribution:

  • Go to the AWS Management Console and navigate to CloudFront. https://github.com/yahyagulshan/linuxnotes/assets/59036269/d0252f84-b74c-4318-bbf9-2a6d0ddfbebb

  • Click on Create Distribution. https://github.com/yahyagulshan/linuxnotes/assets/59036269/8a8eb6ac-6c78-43c6-bc1a-8e31bc659fc2

2 -Configure the Distribution:

  • Set the Origin Domain Name to your S3 bucket, test-12333333344444.com.

https://github.com/yahyagulshan/linuxnotes/assets/59036269/1131da80-38a6-46ec-a065-b12fdd2859de

  • Set the Viewer Protocol Policy to Redirect HTTP to HTTPS.

https://github.com/yahyagulshan/linuxnotes/assets/59036269/e49c9efc-0173-4715-9c31-6879ccfbf39a

  • In WAF (Web Application Firewall), select Do not enable security protections.

https://github.com/yahyagulshan/linuxnotes/assets/59036269/ddf3a97a-6a04-4460-a55d-4569ba4258f7

https://github.com/yahyagulshan/linuxnotes/assets/59036269/d24e5f81-fda4-4fdf-8d9c-73fc7bd1a0b5

  • In Custom SSL Certificate, select the certificate you requested from ACM (test-12333333344444.com).

https://github.com/yahyagulshan/linuxnotes/assets/59036269/6db625ff-0f00-4428-99ae-39e6c494c60c

  • Click Create Distribution.

https://github.com/yahyagulshan/linuxnotes/assets/59036269/627b0161-6626-4793-8b50-2483965f0f53

3 -Set Alternate Domain Name:

  • Once the distribution is created, go to the General settings of your CloudFront distribution.

https://github.com/yahyagulshan/linuxnotes/assets/59036269/fcfd9712-5d4b-4fa6-8201-02a3f0a5a9f4

  • Click Edit and add test.com as an alternate domain name.

  • Save the changes. https://github.com/yahyagulshan/linuxnotes/assets/59036269/b214d29f-fcae-4639-b721-06c295ede312

Step 4: Update DNS Settings

1 -Point Domain to CloudFront:

Conclusion

By following these steps, you can ensure that all traffic to test-12333333344444.com is redirected to www.test-12333333344444.com using AWS services. This setup not only provides seamless redirection but also ensures your site is secure with HTTPS.

Implementing this configuration enhances user experience and maintains a professional appearance for your website. Happy redirecting!