Home > Categories > Aws cdk > Redirect From www to non-www with AWS CDK

Home > Redirect From www to non-www with AWS CDK

Redirect From www to non-www with AWS CDK

Updated:

11 Nov 2020

Published:

11 Nov 2020

When you create website with cloudfront or s3 with custom domain then you may have given www version of domain or non-www version or added both versions.

Your website will work perfectly fine with both versions individually.

And by default www version will not redirect automatically to non-www version.

You may want to setup redirect so your website visitors will see your address without initial www and remember it like that.

To read rest of the article please Purchase Subscription

Before wet get started with CDK I would recommend to develop CDK project inside development docker container.

So we no longer have the issue of "this works on my computer". And it will not mess with your existing workflow.

So checkout my blog post for detailed video explanation.

Then checkout CDK development container settings on github.

To do the redirect

  1. You need to install @aws-cdk/aws-route53-patterns
  2. Make sure you have deployed website/app to non-www domain
  3. Then add following code

Record names is list of subdomains that you want to redirect to target domain.

Download/view redirect full code atgithub

Free users cannot comment below so if you have questions then tweet me @apoorvmote. I would really like to hear your brutally honest feedback.

If you like this article please consider purchasing paid