Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to to solve several CloudFlare 'Page Rules' using only the 3x available?

I have a website, say example.com and require CloudFlare to redirect all traffic from http to https for loads of wildcard subdomains (inc. www); AND the apex (i.e. @ or /) but NOT for for a set of subdomains which are actually CNAMES to 3rd party services for which https is not acceptable e.g.

http://mail.example.com

http://calendar.example.com

http://drive.example.com

http://xyz.example.com

N.B Redirecting to the https protocol for those is not viable as it's not supported by those 3rd party services.

Looking into this, this question solved half my problem. The relevant answer pasted below:

According to Source A;

Page Rules are applied in the order that they are listed. So, all you would have to do is put the bypass cache first and then the cache >everything rule:

nope.example.com/ (Bypass)

example.com/ (Cache Everything)

Each TLD domain cannot have more than 3x Page Rules though, so listing my http only subdomains as individual Page Rules is not possible.

Is it possible to create CloudFlare Page Rule with a logical OR in to target traffic for a specific whitelist of subdomains?

My thinking is perhaps I could express several rules in one string by using a RegEx to target each of the http only subdomains from within one Page Rule.

e.g. as pseudo code with invalid syntax:

http://mail||calendar||drive||xyz.example.com

How would one go about creating a valid RegEx to achieve this?

Thanks

like image 399
Rob McCardle Avatar asked Mar 17 '16 14:03

Rob McCardle


2 Answers

The answer to my question is in fact:

  • CloudFlare Page Rules DO NOT support RegEx
  • The limit on the number of CloudFlare Page Rules is pricing tier specific

I discovered that currently; CloudFlare Page Rules do not support RegEx, Glob or any sort of negation. You can only use basic wildcard * or $1 to pass params.

It appears that if you have the same use case as me you have to just cough up enough money to get more Page Rules and explicitly list all the domains you need a rule for.

Current Rules pricing; 20$ for 20x, $200 for 50x, $$$X for NX - https://www.cloudflare.com/plans

like image 110
Rob McCardle Avatar answered Oct 13 '22 10:10

Rob McCardle


It appears that if you have the same use case as me you have to just cough up enough money to get more Page Rules and explicitly list all the domains you need a rule for. Current Rules pricing; 20$ for 20x, $200 for 50x, $$$X for NX...

Page Rules are now available to purchase a la carte, outside of plan upgrades.

like image 26
RyanK Avatar answered Oct 13 '22 11:10

RyanK