Introducing Page Rules: Fine Grained Control over CloudFlare's Features

CloudFlare is provisioned by DNS. That means that, from the beginning, you've been able to turn CloudFlare on or off on a subdomain level. From the CloudFlare DNS Manager, you can toggle the little clouds next to your subdomains orange (on) or gray (off) in order to control whether traffic for that subdomain will pass through CloudFlare's proxy.

Often, however, users have wanted finer-grained control. For example, you may want to have a CloudFlare app like UserVoice added to your public-facing pages, but not appear on your private administrative areas of your website. Before today, that wasn't an option.

Introducing Page Rules

Page Rules is a powerful new set of tools that allows you to control how CloudFlare works on your site on a page-by-page basis. The feature provides many of the most popular controls of HTACCESS with a user-friendly interface. Page Rules are now available for all users from the Settings menu next to each domain on the My Websites page. Over the next few days we'll be posting some tutorials on the CloudFlare Blog on various ways you can use Page Rules, but I wanted to start with the example above: how to turn a CloudFlare app like UserVoice off on the administrative portion of your website.

Using Page Rules to Control CloudFlare Features and Apps

The first step to using Page Rules is to define a pattern that defines when the rule is triggered. These patterns can be simple, such as a single URL, or complicated including multiple wildcards. Imagine you have a content management system with a single administrative URL:

https://www.example.com/admin.php

If that is the only URL where you want CloudFlare Apps to be turned off, you can enter it in exactly that form as a new pattern. Then, below the pattern, toggle the "Apps" setting to "Off." It's as simple as that.

Wildcard and Advanced Pattern Matching

The pattern above will only match the following URL:

https://www.example.com/admin.php

It will not match any of the following URLs:

http://www.example.com/admin.php[http ≠ https]

https://example.com/admin.php[missing www subdomain]

https://www.example.com/admin[admin ≠ admin.php]

You can make rules more flexible by including wildcards with the * character. For example, if you wanted the pattern to match all four of the above URLs, you could use a pattern like:

*example.com/admin*

A wildcard can represent zero or more characters and can be used anywhere in the pattern. So, for example, the following pattern:

https://www.example.com/*b*/*

Would match:

https://www.example.com/blog/

https://www.example.com/blog/index.php

https://www.example.com/b/admin/folder/index.php

https://www.example.com/myblog/

But would not match:

https://www.example.com/blog[missing the trailing slash]

https://www.example.com/sam/index.php[sam doesn't contain a
"b"]

### Practical Example
Many WordPress users want to disable CloudFlare Apps and performance features like Rocket Loader on their WordPress Admin panel while leaving them on for their public facing pages. To do this, for most default WordPress setups, you can now create a PageRule by defining the following rule:

*example.com/wp-admin*

Then toggle Apps and Performance to "off" then click the Add Rule button. As soon as the rule is in place, your WordPress admin pages will not have CloudFlare Apps like UserVoice included and will not be altered by features like Rocket Loader or AutoMinify.

Non-Trivial

Making this work at our scale is non-trivial. To make sure it is fast, when you create a rule, it is compiled into machine code and pushed out to the edge of our network within a couple seconds. Every rule needs then needs to be checked with every request. Given that, under normal load, we're now processing well over 50,000 requests per second, we needed to put some limits on the number of rules per user. Free accounts include three (3) Page Rules per domain. If you need more, you can upgrade to a Pro account which includes twenty (20) Page Rules per domain.

Over the next few days, we'll be posting other powerful things you can do with Page Rules including how you can use it for advanced URL forwarding as well as ways that it can enable powerful new caching.

During the past year, we saw nearly 2 billion global citizens go to the polls to vote in democratic elections. There were major elections in more than 50 countries, including India, Nigeria, and the United Kingdom, as well as elections for the European Parliament....

Ten years ago, when Cloudflare was created, the Internet was a place that people visited. People still talked about ‘surfing the web’ and the iPhone was less than two years old, but on July 4, 2009 large scale DDoS attacks were launched against websites in the US and South Korea....

Ten years ago, when Cloudflare launched, businesses and organizations purchased expensive on-premise hardware to keep their sites online first and foremost. If they wanted those sites to be faster, or safer, they needed to buy more boxes....

Cloudflare announced today that it has purchased S2 Systems Corporation, a Seattle-area startup that has built an innovative remote browser isolation solution unlike any other currently in the market....