For sites that migrate existing media to R2, it makes sense in most cases to redirect the old URL to the new URL. You are able to do it easily with a single Cloudflare Redirect Rule (in your Cloudflare dashboard under
Assuming your media was stored in the default WordPress location (in the
Rules -> Redirect Rules -> Create Rule
) like so:Rule name | Redirect local media to R2 bucket |
If... | Custom filter expression |
When incoming requests match... | Field: URI Path Operator: starts with Value: /wp-content/uploads/ |
Then... | Type: Dynamic Expression: concat("https://{YOUR_R2_BUCKET_PUBLIC_DOMAIN}", substring(http.request.uri.path, 19)) Status code: 301 |
Assuming your media was stored in the default WordPress location (in the
/wp-content/uploads/
folder), that should handle the redirects without needing to do any config on your origin web server (all handled by the single Redirect rule in Cloudflare).