Title pretty much says it:
I have a Worker site & want to redirect non-www traffic to www
Using Page Rules doesnt work (I assume as the Worker is deployed before the Page Rule takes effect?)
Any other way to implement this?
This is the Page Rule I currently have:
I do my redirects on the Origin Server.
Other page rules works without any problems here.
Not sure why it not works on your side !
Did you try the full URL for Matching
in this case
You need replace
example.com with your own domain !
A page rule matches a URL pattern based on the following format (comprised of four segments):
An example URL with these four segments looks like:
scheme and port segments are optional. If omitted, scheme matches both http:// and https:// protocols. If no port is specified, the rule will match all ports.
Finally, you can disable a page rule at any time. While a rule is disabled, actions won’t trigger but the rule still appears in the
Page Rules app, is editable, and counts against the number of rules allowed for your domain. The Save as Draft option creates a page rule that is disabled by default.
See for more Information about Page Rules URLs
Maybe you have found allready this Step by Step Tutorial that should help you !
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 . 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, Th…
The example they give it literally exactly the same as the image I posted (except mine is permanent)
CF example image:
My example image:
I copied exactly the examples they give in the tutorials, but it doesnt work.
Remember I do not have an Origin Server, this is a Worker site, there is no server it is just html code.
I will try adding https:// to the url to be redirected to see if that makes any difference.
Tried adding https to the non-www url to be redirected and it still fails.
I guess it has to be because Workers are deployed before Page Rules?
But copying the exact what is in the picture will not do it !
As said you need replace
example.com with your own domain
like whistles.com instead example.com
Try the Example but with your own domain and it has to work !
I know that lol, I have many regular websites on CF this is the first Worker site I am deploying publicly
I can get it to work in the other direction.
ie going from www to non-www Page Rule redirect works.
But going from non-www to www doesn’t
Found out what was the problem. an extra dot was needed in my worker as described in this post:
The @ symbol is in this case equal to your root domain. For the routes pointing to the worker, you could remove
example.com/ and example.com/*, as you want them to redirect to www. This should make the page rules for example.com work, too.
Marking this as the solution
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.