Newsletter
TechAnV Blog
Get updates on security engineering, Rust, eBPF, and DevSecOps. No spam, unsubscribe anytime.
Check your inbox and click the confirmation link to complete your subscription.
Cloudflare redirect rules with dynamic expressions#
I wanted to ensure https://niche-museums.com/ would redirect to https://www.niche-museums.com/ - including any path - using Cloudflare.
I’ve solved this with page rules in the past, but this time I tried using a “redirect rule” instead.
Creating a redirect rule that only fires for hits to the niche-museums.com (as opposed to www.niche-museums.com) hostname was easy. The harder part was figuring out how to assemble the URL.
I eventually found the clues I needed in this Cloudflare blog post. The trick is to assemble a “dynamic” URL redirect using the concat() function in the Cloudflare expression language, described here.
1concat("https://www.niche-museums.com", http.request.uri)Here are the full configuration settings I used for my redirect rule:
