Redirect example.com to www.example.com

This tutorial covers redirecting example.com to www.example.com when using Cloudflare, to do the opposite, please see Redirect www.example.com to example.com.

You should replace all instances of example.com in the screenshots with your domain.

Step 1, The DNS Record:
The first thing you will need is a DNS record for @, set to :orange:. This can point to any IP address as the redirection page rule will execute first. I would recommend pointing it to 192.0.2.1, a dummy IP.

Step 2, The Page Rule:
The second step is the page rule that will perform the redirect. You should add one like this:

The * means it will forward all pages and the $1 will keep the path, i.e. if you typed in example.com/page1, you would be redirected to https://www.example.com/page1.

Note: If you have HSTS enabled
If your domain is on the HSTS Preload List, a requirement of this is that your domain redirects http://example.com to https://example.com before redirecting to www. This can be solved by setting the match URL to https://example.com/* and ensuring that Always Use HTTPS is enabled. This means the redirects will be:
http://example.com -> https://example.com -> https://www.example.com
rather than
http://example.com -> https://www.example.com
and therefore satisfy the requirements for your domain to be preloaded.

Thanks for the report of this in this thread.

Introduction to redirecting with page rules video



Tutorial Reference: CT-27

Reviewed: 05/20

This is a Community Tutorial, most are wiki posts, so can be contributed to by Regulars and MVPs here. If there is a tutorial you would like to see, you can request one here.

If you would like to provide any feedback on this tutorial, please post in the #Meta category, tag your post #TutorialFeedback and let us know the Tutorial Reference above.

Other great resources on this community include the Community Tips . These address best practices when configuring Cloudflare, how to fix issues you may see, and tools to troubleshoot. Also you can view Expert Tips, great posts on the community from people in the know that may help you with your issue.

We encourage users to check out these great resources and the Cloudflare Support Centre before posting


7 Likes
Site not open without www
HSTS error for current tutorial of redirecting example.com to www.example.com
Www and root settings conflicting
Community Tutorials
A records IP needed
Error when not using 'www.' for URL search
CNAME registration might be off
Post Domain Migration A Record Question
Using Cloudflare with 3dcart (settings supplied by 3dcart do not work)
Record Not Found
Subdomain issue with A record
Unsecure connection
Problem with the SSL installation
Help Known Issues
Page rule redirects not working - non www to www
Issue with WWW redirect
Requests Through Cloudflare - Only a Fraction Passing Through Coudflare
Issue with sitemaps in serach console and indexing
Pending Nameserver Update 5555
Subdominio
Tips For Google Sites User Who Don't Have GSuite And Wanting Naked Domain
Cant access website at all!
Root Domain or CNAME Flattening
Website Not Loading Without WWW
Need to create two rules
DNS validation Error (code:1004) (URL @ -> www)
Philippinetaxationguro.com
Redirect Non-www to www fail to work
Correct DNS Configuration (cname forwarding)
Adding www
Redirect site non www to www
Redirect ONLY on Main Domain, Not Subdomain
Configuring aws s3 static site
Point domain to sub-domain
Server Error (5xx) for changing to a "WWW"
Custom Page Rule
How to set up EMAIL (MX) and keep CNAME PROXIED (please help)
How to set up EMAIL (MX) and keep CNAME PROXIED (please help)
Do I still need A records mapped to my naked domain if I've setup page forwarding
Subdomain does not point to my site
Error: Err_name_not_resolved
Workers File
ClickFunnels
I cannot get my website to have a valid ssl or work on chrome
Duplicate contents
Can I redirect all traffic to https://www.* with a single page rule?
Redirecting All traffic to Another Domain
DNS page rule problem non-www to www
Target custom domain to github pages
You have to type "www" to get to my page. Why? How do I fix this?
WWW Redirect on Commodore.ca
WWW Redirect on Commodore.ca
Redirect non-www to www
Root domain produces errors or redirects to random websites
Configure domain with "www" to direct correctly
How to redirect (domain).com to www.(domain).com?
How to create a toplevel forward with CNAME flattening?
CNAME & non www to www redirection
Non-www to www not working
How to process non www to www redirection
Root Domain Resolution, SSL Settings, Page Rules Not Working
Trying to get my site without www to redirect to my site with www
I changed DNS to CloudFlare but my website is not running
I changed DNS to CloudFlare but my website is not running
Page Rules Confusion
My site not work
My site not work
525 handshake error
Shopify access ok with www."domain" but not when entering "domain" in browser
Still leading to a NOT SECURE site
My website works with WWW upfront but not without it
301 redirect page rule not working
"Always Use HTTPS" not Redirecting
Breakdiving.io not redirecting to https://www.breakdiving.io
Set up DNS
Non-www redirect to www not working. Could u pls help me?
So long time loading and many errors
Http://theyardsantamonica.com/
Using page rules to perform redirects
HSTS on domain and www subdomain
Adding an A, AAAA, or CNAME record for your root domain
Forward all addresses to https://www
Redirects tools in Cloudflare
Big Cartel domain setup
Vinculacion cloudflare con kajabi
Domain + redirect
Privacy error on Google chrome
Total newbie question - Page Rules / Redirecting
Edit CNAME to move from Samcart to Kajabi - domain not working
Domain redirecting to another domain
Web server is not responding
CF config for Kajabi after moving from InMotion
Forwarding xyz.com to https://www.xyz.com?
Redirecting to subdomain
If I don't use www my website is not found
Force WWW redirect thing
CNAME - root domain to resolve
Error 1014, DNS configuration, and health check errors
301 pagerule
I want the domain to work without www
HSTS error for current tutorial of redirecting example.com to www.example.com
Error 500 - bootstrap site doesn't load without www
Redirecting example.com to www.example.com when using Cloudflare workers sites
How repair that
How to add www. record?
Root domain not working
Big Cartel domain setup
Naked url redirect
DNS issues for domains purchased/registered on cloudflare
DNS Problems whit Site Ground
HSTS & PageRule Problem
Domain not working without www
Purging everything
CloudFlare Certificate on my server
Website Not Configured
How to register cname?
Page Rule to Redirect example.com to www.example.com
Cloudflare has access and i cant open my site
My website doesn't load after I changed my CNAME from godaddy to cloudfare
HELP-- DNS is a mess and need assistance
Confirming correct DNS setup
Workers Site: How to redirect non-www to www?
Issues with DNS - type out www
How to redirect immediately to HTTPS://WWW (without redirect chain)
Add an A, AAAA, or CNAME record
My SIte kep giving 503 error please help
Site Fails to Load on Chrome?
Worker not running
Trouble with Kajabi custom domain and cloudfare
Setting apex record when using Dynamic DNS
First time web developer can't get heroku godaddy and cloudflare to work together
Domain function without WWW
Redirect from NON WWW to WWW
URL Forwarding: non-unique match wildcard redirect
Errors with Domain SSL?
Cloudflare website is unavailable
How to forward an old cdn subdomain to www?
403错误,如何处理
My Site Will not load without WWW
Cname Flattening, using the Apex Domain
Problem with Kajabi, Email, and DNS
Error 401 when I try to edit my web site
CNAME Flattening problem
Redirect all pages to other domain
Complete My Set Up
Page rule redirect
2 redirects to HTTPS
Website Still Unsecure
Redirecting Root domain to Cloudflare hosted site
CNAME to cloudflare-ipfs.com has no orange cloud -- can't apply page rules
How to redirect without DNS A record
Should I add Cloudfare to my Alias domain