CloudFlare Optimization: Two Page Rules Every WordPress Website Needs

CloudFlare is an amazing content delivery network (CDN) with a ton of useful security features. CloudFlare is a great service because it not only delivers static content, but allows you to further optimize your website with page rules. But before I explain what the rules are, let’s address what page rules do and why you need them.

What is CloudFlare?

CloudFlare is not a standard CDN. It actually works as a reverse proxy. Meaning as opposed to a traditional proxy, which sits on the client side, and manages outbound traffic. CloudFlare’s CDN sits server-side and manages incoming traffic from incoming users. The advantage to this method is, it allows it to manage all traffic before any of it hits your server. In addition, it allows them to become an effective web application firewall (WAF) and CDN at the same time.

Page Rules are specific rules that control how CloudFlare treats certain pages. For example,  you can turn the security mode higher for login and register pages. Or you can disable certain optimization features on pages where it has been found to break them. More importantly, though page rules give you access to features in CloudFlare that are not found in other sections of the panel.

In fact, I use Page Rules on almost every site to increase the hit rate of my cache to reduce server load. In addition, it reduces bandwidth and improves the load time for my users.

If you are on WordPress you might have seen some articles recommending to add the “cache everything rule”. This rule will tell CloudFlare to cache everything including HTML files which is where problems start to arise if you use Page Caching. However, you can take the concept of this rule set and another rule to cache all static resources. For instance, if you have a gaming website your Flash files or Unity files are not cached by default. This rule set will cache them to reduce your server load. In addition, if you are serving videos (even if its just a header video), this will apply to that content as well.

Setting Up Page Rules on your WordPress Website

To get started follow the following steps.

  1. Go to your CloudFlare admin panel.
  2. Click on the “page rules” option.
  3. Click on “create a page rule”.

We are going to be making two of them and I will explain why.

For the first rule, you will need to do the following.

  1. Set the domain to as follows: ** In our case, it reads like this **
  2. Go down to the settings. Set the rule Cache Level: Cache Everything.

Now go ahead and make this the first-page rule. This will now cache any uploaded files in your wp-content folder. This is where you should be adding your files and it is where your files are added from the media library.

Now the second rule should read as follows.

  1. ** In our case it reads ** (it might change it to have a trailing slash which is ok as well).
  2. Go to Edge Cache TLL: “A Month”.

This rule now forces CloudFlare to make copies of all your files for an entire month unless manually purged (for all static content). After enabling this you should expect a much higher hit rate for your CloudFlare cache and a major reduction in the amount of bandwidth hitting your web server.

If you would like to consult with a developer about setting up CloudFlare on your website, please contact us.

scott hartley

About the author

Scott is a web performance geek, lover of all things coffee, and avid video game player. His WordPress work delves into web performance, web security, and SEO.

Leave a Comment