Do page rules work with Cloudflare Pages?
I've tried deleting and recreating page rules but none seem to work, do they not work with Cloudflare Pages? For example, i'm trying to redirect www.domain.live to domain.live and it doesn't work
15 Replies
I have the domains setup in a single Cloudflare Pages project
I tried without that in the destination and still nothing
I think your destination URL needs to be https://[your-domain].live/$1
By the way the domain name is at the top of the screenshot.
As others have said, you would need to use $1 to use the wildcard match, not *
You also need a DNS Record created for the page rule to work. For originless records (i.e you're just using redirects), Cloudflare recommends 100::. Create the following record:
AAAA
www
100::
Proxied
and then wait a bit for DNS cache to expire.
(100:: is IPv6 Discard, basically saying if you don't match any of the rules to handle a response, don't go anywhere. If you see a 522, you didn't match anything)
Pages also has a guide on doing this with Bulk Redirects instead of Page Rules: https://developers.cloudflare.com/pages/how-to/www-redirect/Redirecting www to domain apex · Cloudflare Pages docs
In this guide, you will learn how to redirect the www subdomain to your apex domain (example.com). This is a common question and can be achieved by …
Tried that and it still doesn’t work
in what way? What error do you get?
For me, your site does redirect, but it redirects to
https://yoursite.live/$1/hi
What is your dest. url? It should be
https://yoursite.live/$1
Same as before, www.domain.live doesn’t resolve to anything
It's DNS Cache on your end if you are getting that error still
could be local dns cache, or by your resolver. You could try switching to Cloudflare's 1.1.1.1 and clearing local dns cache (depends on OS) or wait it out, shouldn't be more then an hour
Ah ok let me check
What's your dest. URL in your page rule though?
Even once you get that cleared, it looks like your page rule is misconfigured
In bulk redirects this is what I have, following that article
Source: www.domain.live/
Dest: https://domain.live/$1
If you're using Bulk Redirects, you want to follow the screenshot shown in that guide:
(the
/$1
is unneeded)Yep, followed that
Tried with and without $1
Let me remove it again
The DNS Resolution error isn't related to the $1, that was a diff issue
Now it's just that the $1 is there, and redirects go to
https://www.yoursite.live/hi
-> https://yoursite.live/$1/hi
that looks betterAh there we go, thanks!