CloudFlare

 

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

Cf-blog-pagerules

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.

Page_rules_menu_highlighted

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.

New_page_rule

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.

Posted by Matthew Prince
Views | Favorited 0 Times

Comments (14)

Feb 20, 2012
Greg said...
I have always been wondering about WHY is it necessary to turn off Cloudflare on some direcotories such as /admin ? What the reason for that?
Feb 20, 2012
Greg said...
I have always been wondering about WHY is it necessary to turn off Cloudflare on some direcotories such as /admin ? What the reason for that?
Feb 20, 2012
Damon Billian said...
@ dharlow You can actually turn the cloud from orange to grey in your DNS settings for subdomains that you don't want us to touch at all.

Greg:
Some of the performance features can inadvertently break things in the admin panel, such as a visual editor or updating a plugin, so we had to build a solution that webadmins could use to get around this behavior. It was also one of our most requested features over the past year or so...
Feb 20, 2012
Matthew Prince said...
@Greg: you also may have a user-facing App like Uservoice that you want active on the pages your users see, but you may not want it active in your administrative areas. Now you can have it active only on the pages where you want it.
Feb 20, 2012
Greg said...
How about the Google Analytics?How can we go aroudn that one? I have the impression it filters out some information about visitors ..
Feb 20, 2012
dharlow said...
I want Cloudflare on those sub domains, just with different settings then the parent domain. It looks like I can do this to some degree with Page Rules but it would be better if each sub-domain really had its own settings/apps separate from the parent domain.
Feb 20, 2012
Navjot said...
This is what i was dreaming for in Cloudflare. Thanks
Feb 21, 2012
cconover said...
This is fantastic! This is so much easier than going in and editing my Nginx config files through SSH for simple rewrite rules. Cloudflare rocks!
Feb 24, 2012
John Roberts said...
@Greg - you can use PageRules to suppress all Apps, including Google Analytics. Actually, it's all Apps or no Apps right now. (more granularity possible in future)

@dharlow - good to know.

Feb 25, 2012
satx_randy said...
Yea! I love this Page Rules feature. Today am getting hammered on by bots on my blog comments. I had Basic Protection Level set to low, but was blocking a few good prospects, so I turned it off. It'd be great if I could turn it on for my blog and off throughout other parts of my website to stop the spam commenters.
Mar 02, 2012
iamlouisbullock said...
Is it possible to use pagerules to tell cloudflare not to cache dynamically generated images in a directory? I'm using the adaptive-images.com script by Matthew Willcox, and I haven't been able to get it to work with CloudFlare.
Mar 02, 2012
Damon Billian said...
Yes, you should be able to set a PageRule to do exactly that.
Apr 14, 2012
James said...
This potentially sounds excellent. Some of the pages on my site stream videos. Up till now it seems I would have to put these pages in a new subdomain, and disable CloudFlare for those subdomains. For that reason I've not yet activated CloudFlare for that site. Will Page Rules allow me to have video streaming in the main domain instead, and only disable CloudFlare for those particular pages? Or even better, could we disable CloudFlare only for the videos themselves so the rest of the page is CloudFlared? ;) Thanks.
Apr 14, 2012
Michelle Zatlyn said...
Hi James:

Yes, PageRules can definitely help. As you mentioned, create a
PageRule for the URL with the video asset to disable CloudFlare's
performance, security and apps. The rest of the subdomain will get the
benefits of CloudFlare, but your video streaming will be unaffected.

Side note: If the subdomain is currently gray on your DNS Settings
page, you'll have to toggle it to orange for the PageRule to take
effect.

Let us know if there is anything else,
Michelle

Leave a comment...