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

I have an api and traffic in this pattern domain.com/api.php&string1=value1&string2=value2&string3=value3&string4=value4

I’m trying to rewrite the URL so it becomes: domain.com/api2.php&string3=value3&string4=value4

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?

Business

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.