Using url rewrite to append to path

I want to use a url rewrite rule to append /files before certains paths How would i go about doing this
19 Replies
Chaika
Chaika5mo ago
concat("/files", http.request.uri.path)
to be used something like this:
No description
Chaika
Chaika5mo ago
becomes https://yourhostname.com/files/specialpathorsomething/ttt
Paradox_77
Paradox_77OP5mo ago
ah I see, the documentation is a bit spare is there any good resource/documents that shows off url rewrite?
Chaika
Chaika5mo ago
Cloudflare Docs
URL rewrite examples · Cloudflare Rules docs
The examples in this page illustrate how to rewrite URLs with Transform Rules.
Chaika
Chaika5mo ago
really though I think it boils down to two things: The matching is the normal ruleset engine, nothing too crazy, just breakdown your expression as much as possible, almost never using the full url fields, instead hostname, path, and query string functions, with starts_with/ends_with/contains/equals. For replacing, you don't really have too many options. regex_replace is business plan or above which is a bit limited. They are working on a more flexible page rules like regex engine but nothing yet. As it is right now, concat and substring are your two most useful functions, and docs of all the ruleset fields here: https://developers.cloudflare.com/ruleset-engine/rules-language/fields/ you can substring negative either way, if you wanted to get the subdomain for example just substring from 0 to negative the amount of chars in your domain. Same for getting bits of a path, if you know it's a constant length at the end or the start you can grab from there.
Cloudflare Docs
Fields reference · Cloudflare Ruleset Engine docs
The Cloudflare Rules language supports a range of field types:
Paradox_77
Paradox_77OP5mo ago
i so i cant use regex_replace on pro? okay no worries but thanks for sharing all these resources i can use other funtions right? such as to_string?
Chaika
Chaika5mo ago
only business plan or ent
i can use other funtions right? such as to_string?
yes
Paradox_77
Paradox_77OP5mo ago
alright thank you 👍 slightly off topic, but i cant seem to find a general chat to ask this in i cant seem to find brottli where it used to be (Content Optimization) any idea why?
Paradox_77
Paradox_77OP5mo ago
oh thats great thanks @Chaika if i bought the WAF addon id get this right? like it says in the dashboard if i wanted to use the WAF addon for just this would i get different pricing, cuz $200 for url rewrites is a bit outta my budget 😅
Chaika
Chaika5mo ago
What do you mean "WAF Addon"? Are you talking about the Error message saying that you need either Business or Enterprise w/ a specific WAF addon?
Paradox_77
Paradox_77OP5mo ago
yeah, the WAF that isnt zone specific
Chaika
Chaika5mo ago
Enterprise only that would be way more expensive then just Business lol
Paradox_77
Paradox_77OP5mo ago
oh alright ig business it is
Chaika
Chaika5mo ago
you need regex_replace? if so, why not just use Page Rules for now for redirects, and CF has already said they're going to build a better regex system for free before they take Page Rules away
Paradox_77
Paradox_77OP5mo ago
okay ill give that a shot
Chaika
Chaika5mo ago
https://developers.cloudflare.com/rules/page-rules/how-to/url-forwarding/#advanced-forwarding-options yea, page rules has pretty flexible replacement, http://*.example.com/* -> http://$1.example.com/$2 or whatever you need
Cloudflare Docs
URL forwarding | Page Rules · Cloudflare Rules docs
Page Rules allow you to forward or redirect traffic to a different URL, though they are just one of the options provided by Cloudflare.
Chaika
Chaika5mo ago
although those are proper redirects and not just transparent rewrites
Paradox_77
Paradox_77OP5mo ago
yeah i understand, but that might just be enough for me @Chaika i managed to do it with url rewrites using substring and concat it works great thank you so much for all the help
Want results from more Discord servers?
Add your server