Subscribe to receive notifications of new posts:

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

02/20/2012

4 min read

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.

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

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.

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

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.

We protect entire corporate networks, help customers build Internet-scale applications efficiently, accelerate any website or Internet application, ward off DDoS attacks, keep hackers at bay, and can help you on your journey to Zero Trust.

Visit 1.1.1.1 from any device to get started with our free app that makes your Internet faster and safer.

To learn more about our mission to help build a better Internet, start here. If you're looking for a new career direction, check out our open positions.
Product NewsPage RulesDNSSpeed & ReliabilityReliability

Follow on X

Matthew Prince|@eastdakota
Cloudflare|@cloudflare

Related posts