Multiple www to non-www redirection in a single page rule

Hi I have recently added subdomains to support localization for my site and I’d like to use a single page rule to redirect all of them from www to non-www

I’m on a free plan so my page rules are limited


These are the DNS records I have atm. All the subdomains and www are CNAME to @

domain.com, www.domain.com
de.domain.com, www.de.domain.com
fr.domain.com, www.fr.domain.com
jp.domain.com, www.jp.domain.com
es.domain.com, www.es.domain.com
tr.domain.com, www.tr.domain.com
ru.domain.com, www.ru.domain.com
it.domain.com, www.it.domain.com
pt.domain.com, www.pt.domain.com
zh.domain.com, www.zh.domain.com

www.domain.com/* > 301 > domain.com/$1
works great for the one of them

I was wondering if I can use something like

www.*.domain.com/* > 301 > $1.domain.com/$2

I hope that makes sense

Actually, a single page rule should be enough

www.*domain.com/*

However, I assume you do want to use SSL, right? In that case you’ll need the $10/month dedicated certificate from Cloudflare, otherwise all these www.XX hostnames won’t proxy.

1 Like

Thanks, @sandro

all the subdomains have valid certificate right now even on the free plan, that’s why I added them as a CNAME to @ instead of A record. I didn’t need to buy the certificate separately.

I tried this

www.*domain.com/* > doman.com/$1

and got this redirect chain

www.de.domain.com > domain.com/de. > domain.com/de./ > 404
www.fr.domain.com > domain.com/fr. > domain.com/fr./ > 404

I referred to this document and made some adjustments.

www.*domain.com/* > https://$1domain.com/$2

You seem to use the language code as path instead.

You need to post a screenshot of your page rule.

No no, it’s working now. All good

www.*domain.com/* > https://$1domain.com/$2

:point_up_2: this worked perfectly

All right, that’s the rule I mentioned. Just asked because you pointed out 404s.

As for the certificate, it is a bit surprising that it works, as you should get an SSL error. But if it works, it works :wink:

1 Like

You are right. I don’t have a certificate for www.XX.domain.com but I do have them for XX.domain.com,
since www gets redirected, I think it’s all good :slight_smile:

That is my point, you need a certificate for that, otherwise the whole redirect is pointless as you will never reach it (unless you only want HTTP).

I checked it on redirect-checker.org

and it all looks good

Exactly, you sent the redirect on HTTP. Try it with HTTPS :wink:

Ah, I see. You are right.
It makes sense now.

So, if I install the letsencrypt certificates on my server for those www.XX hostnames, can I skip buying it from cf?

Only if you unproxy these www records.

I see, does the pro plan include advanced SSL?
If I’m gonna spend $10/mo, I might as well spend $20

The necessary certificate is independent of the plan. If you want HTTPS for these hostnames and you want it proxied you need the $10/month certificate.

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