Need help migrating BackBlaze B2 CDN cache rule and redirect rules

I am using BackBlaze B2 and they gave a guide on directory browsing by redirecting it. And here is what I did with old Page Rules configuration.

I can successfully migrate the cache rule but I can’t figure out how to migrate the redirect rule. Any help is appreciated.

Regarding migrating Migrate Forwarding URL on Page Rules, you can take a look at this instruction: Page Rules migration guide · Cloudflare Rules docs

Well, I can’t work it out even after looking at the migration guide and I have already tried it before posting here. The example in the guide is so simple but mine is a bit complex. Can you help?

If you just need to redirect everything from *cdn.mydomain.com/file/* to a static URL, you can use something like http.request.full_uri contains "cdn.mydomain.com/file/" as a filter and redirect to https://mydomain.com.

If you need to target precisely *cdn.mydomain.com/file/*/*, then you can use matches operator to filter on http.host contains "cdn.mydomain.com" and http.request.uri.path matches "^/file/$/$", but this requires Business or Enterprise plan.

If wildcards should also be expanded in the URL forwarding destination (i.e. you need to redirect to https://mydomain.com/$1/$2/$3), the easiest way to achieve this is via regex_replace. You can adopt the example from Page rules are now deprecated without good replacements? - #4 by ncano if you have access to this function.

Alternatively, we are releasing wildcard support in Rules this year, so you can keep using Page Rules safely until we have shipped this functionality.

We are also adding more examples to the Page Rules migration guide in the coming weeks to guide users with more advanced use cases.

What you said is suitable for redirecting but it is also redirecting the asset files. I need to let it pass if the url is asset files. I tried with “http.request.full_uri contains the dot (.)” but it didn’t work.

I am sorry if my question wasn’t clear at first. Here are more details.

The cache rule (rule position 1 in the screenshot) was migrated successfully.

But when I tried to migrate the rest of the two rules (rules 2 and 3 in the screenshot), the asset urls cached by the first rule were also captured and redirected to mydomain.com.

In the previous version of the page rules, those 3 rules worked perfectly together. As you can see, the first rule also contains “cdn.mydomain.com/file/” but with extra “*-cdn/”. Therefore, my current expression to catch the request is:

(starts_with(http.request.full_uri, "https://cdn.mydomain.com/") and not http.request.full_uri contains "-cdn") or (starts_with(http.request.full_uri, "https://23lecdn.mydomain.com/") and not http.request.full_uri contains "-cdn") or (ends_with(http.request.full_uri, "-cdn/"))

and then I redirect it to mydomain.com but this doesn’t fulfill 2 things, like the old rules.

  1. it cannot prevent directory browsing unless it ends with -cdn/
  2. The 23le in 23lecdn.mydomain.com can be any other name, and the current migrated rule can only catch what was specified.

Please let me know if my requirements are still confusing.

Did you try something like http.request.uri.path.extension eq "" to exclude assets already? This should prevent directory browsing.

For the rest of your requirements, let’s abstract away from your Page Rules implementation and just focus on the desired behaviour you want to achieve, with URL examples if possible. This should make it easier for us to help you craft the optimal rule.

It says it is not supported when I switch to the expression builder.

with URL examples if possible.

URL examples are in the first screenshot.

But here’s more detail. I am hosting assets (jpg, png, pdf, etc.) for multiple websites on S3. The CDN host can be anything but it will always include “cdn.mydomain.com/file/*-cdn/”. It can be

  1. just cdn.mydomain.com/file/client1-cdn/
  2. or 234cdn.mydomain.com/file/25634-cdn/

and you get the idea. Here is full url for one asset

https://cdn.mydomain.com/file/client1-cdn/path/wp-content/uploads/2024/06/DSC_7133-file-name-520x325.jpg

I want Cloudflare to cache asset URLs like this but I want to redirect to root (mydomain.com) for URLs like following (to prevent directory browsing)

https://cdn.mydomain.com/file/client1-cdn/path/wp-content/uploads/2024/06/
https://cdn.mydomain.com/file/client1-cdn/path/wp-content/
https://cdn.mydomain.com/file/client1/ (without “-cdn”)
https://cdn.mydomain.com/

Please let me know if you need further information. I really appreciate your help.