Issues with Google Sites and www to top level redirect

Hello there! As the title says, I’m new to Cloudflare and I’m struggling a bit to connect the service with Google Sites correctly. When adding a custom domain to Google Sites, you can’t configure the page to be located in the top-level domain: it’s always going to be at www.domain.com. A CNAME record to www targeting ghs.googlehosted.com was added and it works OK: when accessing www.domain.com it resolves and you get the website (as long as the proxy status of the record is set to “DNS only”).

What I can’t seem to solve is redirecting domain.com to www.domain.com so people can enter any of these URLs and get to the same page.

I’ve searched here on the forum for different solutions but I can’t seem to find one. I’ve already created an A record from “@” to the IPv4 address 192.0.2.0, and added a page rule that fowards domain.com/* to https://www.domain.com/$1 (301 permanent redirect). Got ERR_NAME_NOT_RESOLVED. I changed the proxy status of the A record to DNS Only, and got timed out.

I’ve even tried replacing the page rule with a redirect rule, as per detailed in other thread: when hostname equals domain.com, do a dynamic redirect with the expression concat("https://www.domain.com", http.request.uri.path) (preserve query string ticked). Same result: ERR_NAME_NOT_RESOLVED.

What would you suggest I do? Again, the www page works well, what I’m struggling with is the non-www to www redirect. Please let me know if you need more info :slight_smile:

1 Like

Thanks for posting all this information and the links! You helped me get the www.domain.com working for my Google sites, and I was able to figure out how to redirect domain.com to www.domain.com (I didn’t realize I had to disable the proxy). Here is what I have done:

My DNS is only CNAME www ghs.googlehosted.com and the TXT record that Google added. I don’t have any records for the root.

I have 1 redirect rule. if (http.host eq "domain.com") then concat("https://www.domain.com", http.request.uri.path)

I waited a few minutes and it worked. On my mobile browser it seemed to do some caching and that took longer to clear up and work, but now I have both www and root working for my domain and Google sites. Happy to help more