URL Transform isn't working (and I'm feeling frustrated)

I’ve been trying to set up a simple URL transform on my site, Market Cap Stats, within Cloudflare. I have been able to get simple transforms to work, but for some reason this wildcard redirect never works no matter how any times I have tried.

I just want to transform /de/stocks/Cl to /stocks/Cl, so I set up a rule to catch /de/stocks/* to /stocks/$1.

I can’t for the life of my figure out why this is not working. Any help would be greatly appreciated!

Have you tried with http.request.uri.path instead of http.request.uri? Also based on this you don’t need to rewrite the Query section.

1 Like

Can’t provide much in the way of examples as I’d need to check it’s actually correct, I’m on my mobile, but…

  1. You can’t use *, but you need to use the actual correct language and syntax (examples, including what you are trying to do, here: URL rewrite examples · Cloudflare Rules docs)
  2. You need to use http.request.uri.path.
  3. You need to use Dynamic rewriting, with the actually correct syntax (see link above).
  4. You don’t need to rewrite the path as it’s been already said above.
1 Like

Thanks for this! I have gotten it to partially work with http.request.uri.path as you suggest and also read through the examples (before and after posting here).

I just need to find a way to transform /de/stocks/* to /stocks/*. I figured out how to do it with regex and am looking for a solution without regex.

I’m assuming that regex will be required here since I am deleting part of the URL, not adding?

The way is with regex, there is no other way… what would be the issue with having a regex there?

You can do it without a regular expression but you need to be careful.

This rule will discard the first three characters of the path, so if you ever change the prefix to e.g. /en-us, you’d have to change the number to 6.

The regex_replace() function is only avaiable on BIZ and ENT.

2 Likes

This worked! Thank you so much! I looked through the documentation and did not see substring(). It’s exactly what I needed for my use case.

And yes, I’m trying to avoid upgrading to BIZ for now. I won’t say it’s on purpose, but the documented examples tend to heavily favor regex. :wink:

Yeah, it’s not in the documentation. I doubt it’ll be removed but it’s always a risk with undocumented features.

1 Like

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