Caching 301s from origin

I have a Wordpress server running on Apache that produces a number of HTTP 301 redirects. However, while Cloudflare caches page content, it doesn’t seem to cache 301s themselves, meaning any request that hits a 301 has to do a round trip to the origin before hitting the cached page in Cloudflare. Below is an example in curl. What is the best way to get Cloudflare to cache 301s?

* Connection state changed (MAX_CONCURRENT_STREAMS == 256)!
< HTTP/2 301
< date: Sat, 08 Jan 2022 16:16:11 GMT
< content-type: text/html; charset=UTF-8
< location: https://domain.com/page/
< cf-ray: 6ca6ba989ab08003-IAD
< cache-control: max-age=86400
< expires: Sat, 08 Jan 2022 17:16:11 GMT
< strict-transport-security: max-age=2592000; includeSubDomains; preload
< vary: Accept-Encoding,Cookie
< cf-cache-status: MISS
< cf-apo-via: origin,resnok
< cf-edge-cache: cache,platform=wordpress
< expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
< x-redirect-by: WordPress

I have confirmed that the origin does set an Expires header. The wordpress installation is also running the Cloudflare plugin.

< HTTP/1.1 301 Moved Permanently
< Date: Sat, 08 Jan 2022 16:27:32 GMT
< Server: Apache/2.4.41 (Ubuntu)
< Vary: Accept-Encoding,Cookie
< cf-edge-cache: cache,platform=wordpress
< Expires: Sat, 08 Jan 2022 17:27:32 GMT
< Cache-Control: max-age=3600
< X-Redirect-By: WordPress
< Location: https://domain.com/...
< Content-Length: 0
< Content-Type: text/html; charset=UTF-8

Without knowing the actual URL you’re testing, it’s difficult to diagnose. Is there a query string?

Sorry about that - one URL is https://nofap.com/about which 301s to https://nofap.com/about/. No query strings though.

That must be something about APO. I use a Worker for my site caching, and it’s similar to how APO works, but it caches my 301 request:

Ah, here’s the explanation:

My advice would be to use Bulk Page Redirects if you don’t want those hitting the origin.

https://developers.cloudflare.com/rules/bulk-redirects

1 Like

Gotcha, so this would be a hard coded list of redirects, not cached from the origin per se? Alternatively, can you combine workers with APO?

Yes.

Search function here says yes.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.