Dynamic Transformation Rule help

Suppose i have this. url

https://example.com/wp-content/uploads/2022/06/sample.png

I want to rewrite to

https://static.example.com/my-bucket/prefix/uploads/2022/06/sample.png

How can i create rewrite rule?

I can do the first half where i can write if uri contains but i am nots ure how can i dynamic field to chnage the hostname and complex uri path edit

You can try following the example here:

https://developers.cloudflare.com/rules/transform/url-rewrite/examples/#rewrite-path-with-several-url-segments-to-a-different-url-segment

But note that you want to rewrite the entire URI, not just the path, so you’d want to use http.request.uri and not just http.request.uri.path.

This can be done with Host Header and/or Resolve Override in Page Rules if you have an Enterprise plan. Otherwise you will have to use Cloudflare Workers.

1 Like

Good callout - I should clarify that using a regular expression in Transform Rules is a Business plan (or above) feature:

https://developers.cloudflare.com/rules/transform#availability

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