I’m using Cloudflare on a WordPress install (hosted w/ WPEngine).
Using a custom worker, I’m attempting to cache certain requests sent through to a series of custom endpoints set up using the WordPress REST API. These are GET requests and the response is JSON.
Cloudflare is properly caching the requests, however, I’m having issues w/ clearing them. A purge of everything works properly and I see the cf-cache-status header change as expected.
Specifically, it appears that ‘wp-json’ in the path is causing the issue. If I alter the path (e.g. wp_json), I’m able to perform a custom purge w/ the new altered url/cachekey.
I assumed maybe it was related to WAF, but nothing shows up in the logs and disabling the firewall completely (this is in a staging environment) does not fix the issue.
Have you blocked access to or added authorization to your REST API endpoints (like /wp-json/) via functions.php or any other plugin limiting your access due to the security concerns and possible sniffing the lists about the users and authors?
Hi @fritex - hmmm, we are using Wordfence which seems to limit access somewhat. Disabling the setting doesn’t seem to fix it and I don’t see any other options related the REST API.
I’m kind of thinking the same thing you are. Namely that somewhere this request is being restricted in some way. Just not sure where.
Not a big deal. I ended up modifying the request URL so that it doesn’t get filtered.
You cannot pass the request or you got the 404 error when trying to access that URL?
Have you recently updated your “Permalink” structure under the WordPress settings?
Try setting the permalink structure in the wordpress and also if needed changing the .htaccess to make permalink work correctly if not.
Moreover, if not, try to click on “Save” and see if you can access it again.
And if the wp-json endpoint is not being already blocked via security or firewall plugin.
Moreover, which WordPress version do you have?
The new REST API (wp-json) endpoint for Wordpress 4.7 is like example.com/index.php/wp-json/. It’s part of Wordpress Core as of 4.7 till newest one as far as I know (5.5.3 or 5.6 already).
Nevertheless, if we have “Cache Everything” enabled, should the cache work.
And then a Page Rule to … hm, which plugin do you use, if so, to purging cache at your end or you just want to achieve when you open the wanted URL which contains /wp-json/ with some parameter and value to trigger the Cloudflare API to purge the cache for something?
Yes WP Cloudflare Super Page cache will bypass the /wp-json endpoints whether you setup the plugin with the default page rule mode or enable the Worker mode inside the plugin settings (Cache Tab).