Need Page rule advice

I have an application with the following URL structures:

  1. example.com/en-us
  2. example.com/en-ca, etc.

These are the application home pages for different regions.
I want specific cache rules for example.com/en-*.
But I don’t want to Cache anything under example.com/en-*/.
The page example.com/en-ca/ redirects to example.com/en-ca which is handled at the application level.

Hi there,

You would need to have the most specific URL on top. In this case:

  1. example.com/en-ca/
  2. example.com/en-*/*
  3. example.com/en-*

I am not sure if the en-ca bit would need a Page Rule here, but if it does that would be the order. Keep in mind that only one Page Rule will be matched per request.

I hope this helps. :slight_smile:

3 Likes

I’am afrait with CloudFlare PageRules we just have the option to use asterix (*) as a wildcard which acts like a kleene star at RegEx. Therefore you do not have any control over how many “wildcard chars” are beeing matched unlike at RegEx for example:

WildCard:

*
Matches unlimited random chars

RegEx:

.?
Matches unlimited random chars

.{2}
Matches 2 random chars.
(actually that what you want)

This apparently is not possible with CloudFlare.

You will have to create a single PageRule for every URL to match it exactly, as you can not match the wanted URLs directly without anything else NOR the exact oposit to exclude the exact oposit of what you want from a rule.

I personally would love it if CloudFlare would provide a bit more flexibility when it comes to operators. Something very easy like:

example.com/en-(au|bz|ca|cb|gb|ie|jm|nz|ph|tt|us|za|zw)/
which matches with an OR operator explizitly ALL your possible sub-languagecodes for englisch language.

or something like this:

example.com/en-(.{2})/
OR
example.com/en-*{2}/

which means just 2 random chars.
But chances are low this ever will be implemented.
A little workaround is. Set differenciate the language based on the FQDN and take a different Subdomain for each different language.

Like:

  1. en-us.example.com
  2. en-ca.example.com

These would be matchable with:

Pattern: en-*.example.com
Rule: Cache Everything

This would not match way more as the function of the wildcard is limited to the range of the subdomain - if you understand what I mean. This rule then would just match the rootPage for all languageRootDirectories (startage of all languages then in Cached)

The more often I read your question the more I think I missunderstood your requirement. If that is the case just explain it again.

1 Like

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