Root domain redirect to www


Is it possible with Cloudflare to redirect all requests coming to root domain (A Record) to www subdomain without even hitting my server?

So I have www subdomain setup served by S3 + Cloudfront (for SSL) and I just want to completely bypass my own servers (looks like I still need it for redirecting root domain to www)


Yes! You probably already have a DNS entry for your root domain. Now, add a Page Rule:

Match:* and Redirect (301) to$1

Or http if you’re not using SSL. The $1 means to copy the path from the original request.

p.s. Make sure the root and www DNS entries are set to :orange:


Thanks sdayman, I have exactly same setup, but when I run:

$ curl -I
HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Tue, 15 May 2018 19:48:59 GMT
Content-Type: text/html
Content-Length: 178
Connection: keep-alive

I see in my nginx logs: - - [15/May/2018:22:48:59 +0300] "HEAD / HTTP/1.1" 301 0 "-" "curl/7.58.0"

My root domain A record has enabled CloudFlare proxying. So this is really strange. Maybe CloudFlare actually isn’t proxying domains with A records.


I only checked one of your zones, but it has Match: as opposed to Match:

Also if your record is orange clouded and you’re using public DNS for resolution you shouldn’t see Server: nginx in the response. So I suspect either the record isn’t orange clouded or you may be testing from a machine which isn’t using Cloudflare’s DNS for resolving that host name.


I note that the curl command didn’t actually return any Cloudflare
headers, there should be a Server: cloudflare and a CF-RAY: header.

You unfortunately X’d out useful information, but I’ll bet the request
came from your IP and not a Cloudflare IP, is that correct? Perhaps
you’ve used a local hosts file or similar to override the DNS
resolution? Or perhaps you have your domain paused in Cloudflare?


Thanks everyone, especially thedaveCA. I forgot I had /etc/hosts entry for this domain as I need to access it not only via HTTP/HTTPS.

Thanks again for your fast answers!


It’s easy to forget. I know I’ve done it.

closed #8

This topic was automatically closed after 14 days. New replies are no longer allowed.