Trying to use url rewrite to strip strings from URL before caching

I have an api and traffic in this pattern

I’m trying to rewrite the URL so it becomes:

Then I want to have a page rule that will cache everything at api2.php, so regardless of the string1 and string2,cloudflare will return the same result for users from cache.

Because the clients using the API already can’t be changed, we can’t change this on our side in a way that is not transparent to the clients.

That’s why I got interested in the URL rewrites… but I don’t seem to get it right.

This is my redacted regex for query rewrite dynamic

regex_replace(http.request.uri.query, "^.*&value3=(strings|strings)&.*string4=([0-9]+).*$", "value3=value3&string4=${2}")

But it seems cloudflare is either not rewriting it, or not applying the page rule to the transformed url (cache everything at api2.php).

Any help?

Are you on a Business or Enterprise plan?


1 Like

I’m really weak at regex, but at least you’ve confirmed it’s supported on your plan.

I was checking my nginx access logs and I do not see the rewritten URLs in my logs is that expected?

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