Cloudflare can be used in innovative ways to improve the performance of your site. The most obvious use-case is of course, the caching of static assets, but there are so many other functionalities. For example, page rules are some of the most impactful features that Cloudflare offers. We can use them for caching, forwarding, disabling performance on specific sections, and more. In this article, I’ll share some of my favorite Cloudflare page rules that I use on my website WP-Tweaks.com.
Full Site Caching with a Plugin
These page rules aren’t set by you manually, but through a plugin. I’d written earlier about how I managed to achieve TTFB rules of under 0.5 seconds using the WP Cloudflare Super Page Cache plugin. Use this plugin only if you have a mostly static website that doesn’t change a lot, though the plugin also has settings for WooCommerce, so you can still give it a go.
These page rules are set via an API, so you don’t need to make the changes manually.
Forwarding to “www”
A lot of sites explicitly want their visitors to use “www”. So they’ll set up redirect rules in .htaccess rules to enable both www and https. The idea is for a request like this:
example.com
to become
https://www.example.com
I’d written earlier about how to redirect all traffic to the preferred “https://www” version using just one htaccess rule instead of multiple ones. That’s still a good thing to do, but you can save yourself some server load by outsourcing the logic to Cloudflare’s EDGE servers instead. To do this, we have a page rule like this:
This page rule takes a “non-www” URL and instantly makes a 301 redirect to the “https://www” version as shown above. It’s typically much faster than an .htaccess rule because it’s handled by the closest Cloudflare EDGE server!
Note that we’re not intercepting “http” requests. That’s because there’s already a setting in the Cloudflare section labeled SSL/TLS -> “Edge Certificates” called “Always Use HTTPS” that looks like this:
Enabling this option automatically uses the HTTPS protocol for all your assets – not just your pages, but also your images, CSS and JS files. So this part is already taken care of, and now we just need to deal with the “www” aspect.
Forwarding Affiliate URLs
If you’re running an affiliate site, you can use Cloudflare for blazing fast redirection. For example, I have page rules set up like this:
I use the “ThirstyAffiliate” URLs (like so many others), that cloaks my affiliate landing pages. Using Cloudflare rules, we can easily redirect them without needing to rely on your origin server. It works great! Every additional second wasted is a potential lost sale. Let Cloudflare help you avoid that!
Disabling WordPress Admin Areas
I’d written earlier about whether I thought the Cloudflare “Pro” plan was worth it. The WAF is a huge benefit, and it works really well. However, it sometimes blocks legitimate requests from the WordPress admin section, preventing posts from being saved in Gutenberg. To avoid this, we can disable security and performance in the admin section as shown here:
This neatly avoids all false positives from occurring when you’re trying to edit your site!
20 Page Rules with Cloudflare Pro
The free version of Cloudflare only gives you 3 page rules to play with. That’s not enough for all the things I want to do on my site. The Cloudflare Pro plan however, allows me a generous quota of 20 page rules, and that gives me a lot of breathing room. I don’t really have to worry about not being able to do everything I want.
But if you’re still on the free plan, you’ll have to pick and choose which ones are important to you. Personally, I would choose full page caching, forwarding your most important affiliate URL, and one more. I hope you find the right balance that works for you!
I’m a NameHero team member, and an expert on WordPress and web hosting. I’ve been in this industry since 2008. I’ve also developed apps on Android and have written extensive tutorials on managing Linux servers. You can contact me on my website WP-Tweaks.com!
Andrew Burkman says
i am new to cloudflare and this was helpful figuring out the best page rules. Thanks