Cf caching not working with origin generated 403 404 pages?


Have a website behind Cloudflare. “Cache Everything” is enabled in a page rule for the whole site.
Some folders on the origin are protected by .htaccess rewrite rules, so access to the .html files in those folders is only allowed when referrer is the origin server. If those folders are accessed from any other server the origin presents the default standard 403 Forbidden page.
This all works as expected.
My question is: Am I correct in assuming that cf caching is not working for the standard 403 Forbidden Page, since this page is not first requested by a client, but presented by the origin server based on the .htaccess rule?
If cf caching does not work in this case, is there a way to enable it for origin generated 404, 403, etc. pages?

Cloudflare by default caches certain file extensions (like css, js, jpg etc). If the response is a 404 or 403 the response will be cached for 3m and 1m respectively, if there is no other cache-control header.

If your 403/404 URLs do not match the standard file extensions, you will need to have a Cache Everything page rule.

This is described in more detail here:

Thanks for your answer. But if cf cache them for a certain amount of time, I wonder how cf ‘knows’ where to find the 403 and 404 pages on the origin server.
Those pages are not requested, but offered in case a request for another page can’t be fulfilled.
In my case they are the standard pages (not custom versions) so ‘made’ by Apache on the fly.
Triggers cf on a 403/404 header and then cache the response html code coming with that type of header?

Cloudflare does not need to know where your error files are, or what URLs result in an error. Every time Cloudflare ask your Apache for a file Apache delivers some payload along with the HTTP status code. Whether that is a file from disk or a special error page is entirely up to you and your Apache configuration.

1 Like

This topic was automatically closed after 14 days. New replies are no longer allowed.