Page rule forwarding with subdomain and wildcards

Hello folks

I have a question / challenge for you out there:

I am looking for a solution using page rules (if needed also CNAME records) to achieve following 301 - Permanent Redirects:

* "www.example.com" --> "https://example.com"
* "www.example.com/site1" --> "https://example.com/site1"
* "www.subdomain.example.com" --> "https://subdomain.example.com"
* "www.subdomain.example.com/site1" --> "https://subdomain.example.com/site1"

In other words, I want to drop the “www” part for all possible scenarios.

I did have part success with the rule:

https://www. example.com/* Forwarding URL (Status Code: 301 - Permanent Redirect, Url: https://example.com/$1)

But this does not do the trick with subdomains for me. I tried a second rule:

www.*.example.com/* Forwarding URL (Status Code: 301 - Permanent Redirect, Url: https://$1.example.com/$2)

but this is not working unfortunately…

Who can help me solve this?

Hi @TRACKTICS,

That looks like Subdomain too deep to me.

1 Like

Hi @domjh

It seems like this explains it all… thx for the ultra fast answer!

In that case I’ll set up CNAME records in the style of:

CNAME | www.subdomain.example.com | subdomain.example.com | Auto | DNS only

for now…

1 Like

No problem! You either need the $10/month cert from Cloudflare, or to set the record to :grey: as you said and handle the redirect on your server. Just note that with it set to :grey:, you are bypassing Cloudflare and your origin IP will be visible.

Since the target is usually an AWS Cloudfront or load balancer, I am not that concerned since that already has it’s own protection layer…

I’ll think about the $10/month investment if it grows to more than just 2-3 DNS records for that reason…

1 Like

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