Redirect example.com to www.example.com using Single/Dynamic Redirects

Background:

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

Looking for the opposite? Redirect www.example.com to example.com using Single/Dynamic Redirects

Prerequisites
  • Have an active and setup website in Cloudflare. Transfer your website to Cloudflare today, or use the Cloudflare Registrar to register a new domain.

  • I will be using example.com in place of your real domain. Anytime this used, please replace it with your own domain.


Guide:

  1. Navigate to your website in Cloudflare, and then to DNS → Records. Magic link.

  2. Add a new record. The type should be AAAA (IPv6 type), the name should be @ (shorthand for your domain name), the IPv6 Address/value should be 100:: (IPv6 Discard, if nothing handles the traffic in Cloudflare, it won’t go anywhere), and Proxy Status should be on :orange:.


    Make sure to click Save.
    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.

  3. Navigate to Rules → Redirects → Create Rule. Magic link

  4. 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.


    Then click Deploy.

  5. Wait a few minutes and test the redirect.


Troubleshooting:

  • 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 — One of 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.

7 Likes
301 permanent redirect from root to www not working
Cannot get site/domain to work without www
Can't get my page to forward
Quiero poder "Cambiar DNS o Cambiar servidores" a hostingator por favor ayuda
Transform Rules - Please help
ContactPoints.io works on desktop, but not mobile
Too many redirects when publishing a google site
SSL handshake failed on some pages only
How do I create a redirect from core domain to subdomain?
Cloudflare domain fails to load as naked domain
How to forward a URL address to another
New DNS A records no updated on Cloudflare's DNS servers
GoHighLevel CloudFlare SSL Issue, Website Will not load
DNS not updating - Nationbuilder
Invalid SSL certificate Error code 526 due to recent changes
Google Site is Linked, But Connection Times Out
525 Error SSL handshake failed
Problem with redirect
Redirect not working for deluxlures
Getting a 1016 error on a new domain we want to redirect to our main one
Can't unlock configuration to transfer domain
Connecting my googles sites to my domain name
WAF Blocking rule not working
How do I correct a 1014 Error? my website is not showing up
My site is not working on domain
In need to redirect all traffic going to blesvcs.com to www.blesvcs.com to stop 404
SSL Not Working For root domain but working for www.domain.com
Unable to Redirect naked domain to www version
My traffic data is not showing in Cloudflare (Domain hosted with Cloudflare)
Cname for root domain not publishing
Website only loads at www. address
How to redirect wcpartners.org to www.wcpartners.org
Connection google site to cloud flare
Failure (Re)directing new CF URL to my Notion Website URL
Could not convert http to https
How to redirect root domain to www?
Got a domain name from o2switch, need to redirected to a SumUp shop with CNAME
I have a problem with DNS and my site is not working
Zero unique visitors in stats all of the sudden
Website is down - DNS and redirect problems
Total newbie in desperate need of help
Trying to redirect to another site: CNAME Cross-User Banned
Redirecting issues
Fuciona www.informacion-menopausia.com pero informacion-menopausia.com no
New to cloudflare and added website but it's not working
Www. not loading and I have no IPv6 address to redirect! Please Help!
Www. not loading and I have no IPv6 address to redirect! Please Help!
Access website without www
Message says "flattening not available for this domain"
Heroku hosting & A domain from registrar
Website down completely - Error: DNS_PROBE_FINISHED_NXDOMAIN
I have set the required DNS records to link the domain to Google Sites, but the web
Connecting my Google Site with my Domain
I don't see and/or can't register the "A" DNS records cause it already exist on DNS
Site is not loading (google site)
Cloudflare & Kajabi connection
Redirect naked domain to WWW domain
URL Not Redirecting VKatip.Site
DNS help for domain root
Https is automatically doubled when not adding www befofe my website domain name
I’ve never seen a system work this hard to stop customers from opening a case
Redirect root to www
Redirect root to www
Can't access domain from smartphone
At end of my rope: SSL handshake fails, host error
My site works with www.example.com but not with example.com
My website is offline after transferring from Ionos
My site works with www.example.com but not with example.com
Error 1000 - prohibited IP issue
Verifying Domain with Google
🗂️ New: Rules Templates (in one click!)
Redirect one domain to main domain
Continuous Error with Custom Domain Configuration
Unique https// to https:www Redirect
How to redirect non-www to www with Redirect Rules
After 24 hours, my name server did not updated
Can't access my site without www

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.