By default, Cloudflare only allows Free users to setup 3 Page Rules. These page rules are what allows WordPress users to differentiate which pages/files etc. should be cached and served from Cloudflare servers and which should be served from the original web hosting.
My old Page rule setup is as shown below. Number 2 prevents my wordpress admin dashboard from being served via Cloudflare while every other part of the website is served via Cloudflare.
With Page Rules, there’s a limit to how many URLs you can setup, but this isn’t so with Cache Rules. With just 2 of the 10 Cache Rules offered for free, you can setup a lot of URLs as I’ll show soon.
Here’s what my Cache Rules page looks like.
The first one Cache Everything is targeted towards caching everything on the site on Cloudflare servers. Simply click on Create Rule to begin then replicate everything in the screenshot below whilst replacing domain name with yours.
When you’re done, click on Deploy and it will go live.
My second cache rule is targeted towards excluding special parts of my WordPress installation from being cached by Cloudflare. This includes WP Admin, WP Login, Sitemaps, Search Pages, WordPress Cookies, URLs etc.
Below is what my current setup looks like. You can click to enlarge.
If you wish to not edit each line one by one, simply proceed as follows. Create a new Cache Rule, give it a name and then click on Edit Expression
Copy and Paste the following rules below into the field.
(http.request.full_uri contains “/wp-admin”) or (http.request.full_uri contains “/wp-login.php”) or (http.request.full_uri contains “https://www.YOURDOMAIN.com/?s=”) or (http.request.full_uri contains “/checkout/”) or (http.request.full_uri contains “/cart/”) or (http.request.full_uri contains “/my-account/”) or (starts_with(http.request.full_uri, “/graphql”)) or (starts_with(http.request.full_uri, “/xmlrpc.php”)) or (http.cookie contains “no_cache”) or (http.cookie contains “wp-“) or (http.cookie contains “wordpress-“) or (http.cookie contains “comment_”) or (http.cookie contains “woocommerce_”) or (http.cookie contains “PHPSESSID”)
Don’t forget to replace YOURDOMAIN with yours
Under Cache Eligibility select Bypass Cache then save as draft or deploy.
If you wish to exclude more URLs, simple click on OR at the end of the last added URL. Select URI Full then Equals and enter the full URL and save.
Deploy the two rules you’ve created and make sure to arrange them is such a way that Cache Everything is the first listed Cache Rule.
If you’ve got questions, hit me up in the comment section.
Please rate & share this article to help others. Thanks
You’ll also like:
- FIXED! How To Edit WP-Config While Using Cloudflare
- How To Use Custom Theme With Jetpack Mobile Theme Feature
- How To Setup Hyper Cache On Shared Hosting Server
- How To Setup Google Page Speed On Hostgator Servers
- How To Fix CLS - Core Web Vitals Issues Caused By Google Adsense