website icon indicating copy to clipboard operation
website copied to clipboard

www -> root domain redirect Cloudfront clash

Open vinnyt123 opened this issue 3 years ago • 0 comments

Following the tutorial for a www -> root domain redirect (e.g www.example.com -> example.com) https://serverless-stack.com/chapters/setup-www-domain-redirect.html, it directs you to set up a new cloudfront distribution for the www subdomain.

This means the www subdomain can no longer be an alternate domain name (CNAME) record for this cloudfront distribution or this error occurs on deploy:

Error: The domain "www.example.com" is already in use by another website or CloudFront Distribution.
    at updateCloudFrontDistribution (/var/task/utils.js:688:13)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)

This is caused by https://github.com/serverless-components/website/blob/6f87650a476e318572209bce9b5403f71643485b/src/utils.js#L103-L104 automatically adding the www alternate domain name (CNAME) record when it is not wanted in this case.

I suggest an option should be added to not include this www alternate domain name (CNAME) for the cloudfront distribution as it makes this style of www redirect impossible.

vinnyt123 avatar Apr 27 '21 10:04 vinnyt123