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 by way of CloudFlare.
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 using Single/Dynamic Redirects
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 via the link below
- Please note that due to DNS Cache, you may not be able to instantly connect and see the redirect. It may take an hour or so. Your Default DNS Resolver, usually operated by your Internet Service Provider, may cache for longer. Consider switching to Cloudflare’s 1.1.1.1 DNS Resolver today, for fast and privacy respecting DNS. Setup instructions: 1.1.1.1 — the Internet’s Fastest, Privacy-First DNS Resolver
This will manifest with errors such as “We’re having trouble finding this site” or ERR_NAME_NOT_RESOLVED or DNS_PROBE_FINISHED_NXDOMAIN . - If you would like to provide any feedback on this tutorial, please post in the #Meta category, tag your post #TutorialFeedback .
Curated: https://www.SoftwareHunt.io
Popular Links
Curated by www.SoftwareHunt.io