Why doesn't server rewrite work behind Cloudflare?
1 min read · Last updated June 2026
Server rewrite serves different image bytes from the same URL depending on each visitor's Accept header. Cloudflare ignores that signal by default and caches one format for everyone. The fix is to switch to picture-tag delivery.
Symptom
Behind Cloudflare, some visitors get a format their browser can't open, and others only ever receive the original JPEG or PNG even though their browser supports AVIF or WebP.
Cause
Server rewrite reads the browser's Accept header and returns AVIF, WebP, or the JPEG or PNG to match. It also sends a Vary: Accept response header — a cache signal that means "the right response here depends on the Accept header, so store a separate copy for each value."
Cloudflare ignores Vary: Accept by default. It caches one response per URL, and whichever format the first visitor triggered is what every visitor receives after that.
Fix: switch to Picture tag
Switch your delivery setting to Picture tag, the plugin's default. Each format gets its own URL — photo.jpg, photo.jpg.webp, photo.jpg.avif — so a CDN caches each one separately and no header negotiation is needed.