How to properly build a Root Website Redirect to www on CloudFlare.com

We have spent quite a bit of time finding this solution, so much of the data that is out there is to much of a summary or not clear to proper operation of a root domain to www redirect.

Often times when subscribing to SaaS based services and provide a cName redirect for your domain the provider will only support a subdomain such as www.yourdomain.com via cName that leaves your root domain open to if someone just puts your domain in first time around without the www (most modern browsers will remember the www)

However with the solution below, even from the onset if there a root domain request such as domain.com it will provide a dynamic redirect to www.domain.com

Redirect example.com to www.example.com (root/apex to www subdomain) using Single Redirects (also called Dynamic Redirects).

AAAA Record using IPV6 : Originless record for Single Redirect

This will allow traffic to flow into Cloudflare and hit your Redirect. Cloudflare will serve its own Proxy IPs at edge, so both IPv4 and IPv6 Clients (everyone) will be able to connect.

Create your Redirect Rule. Give it a name, like Redirect root to www subdomain , and select Field: Hostname Operator: equals , Value: example.com .
Under “Then… URL Redirect”, change Type to Dynamic and add the following expression concat("https://www.example.com", http.request.uri.path) , check Preserve Query String . Replace any mention of example.com with your own domain.

All steps and diagrams of zone records click link via CloudFlare Community)

https://community.cloudflare.com/t/redirect-example-com-to-www-example-com-using-single-dynamic-redirects/636762

Curated by www.SoftwareHunt.io

Visit https://www.SoftwareHunt.io