Making Page Rule wildcard non-greedy

Hey folks,

I’m wondering if there is a way to have a non-greedy wildcard in page rules?

For the sake of an example, I’d like to redirect*/* to$1/test/$2, where the first * matches one path segment, and the second * matches anything else. So, if I were to request, I’d get redirected to

I’ve configured the page rule as above, but currently if I request it gets redirected over to

Is there a way to have a non-greedy wildcard in Page Rules? This feels like a super basic thing but I can’t figure it out :frowning:


Each * corresponds to a $.*/* → the last * matches even something after like /3/4/5/6/index.html.

Would be*/*/* → forward to$1/$2/test/$3/.

You do have both cases, like /1/2/ and also combination like /1/2/3/ and maybe more segments? :thinking:

Either try to split it and use multiple Page Rules to catch that cases (just make sure to keep in mind the priority & order of the Page Rules) or, I might not be sure if something could be done with Transform Rules if that so.

And the amout of available Page Rules for use is related to the Plan you’re using.
Except, if we need we can purchase more Page Rules for $5 individually.

Also, Cloudflare Page Rules don’t support RegEx :confused:

Nevertheless, leaving here the below article for some clarification:

Patiently wait and maybe someone else might have the better answer.

I do not believe that is the case…

My page rule is defined as*/*$1/test/$2.
If I request, it is redirected to

It seems that it is actually the first * that matches all the extra segments, not the last *. The behaviour that I desire would be for the last * to match extra segments.

The article you linked does seem to confirm this, the first * will be greedy (matching to the end of the URL), and then it back tracks from the end to match /*, so that second * only matches the final segment.

Rather annoying behaviour. Would be great to support something similar to RegEx’s lazy/non-greedy operator.

Unfortunately, Page Rules doesn’t support RegEx at any plan level.

If it’s not an extensive list of directories, you may try Bulk Redirects:

Best to handle complex redirects at the server, or possibly with a Worker.

1 Like