Redirecting multiple subdirectories into multiple, equal subdomains
What steps have you taken to resolve the issue?
We have looked into options to create a snippet, URL transform rules and page rules, but keep running into either limitations of the free plan (no regex) or knowlegde (snippets). We currently have set up a bunch of rules for languages to be translated from (for instance) url.nl/de to de.url.nl, but we have more than 25 languages which is the max amount for our subscription.
Bsically, the idea is to rewrite all urls that contain language codes like /en/ but also www.url.nl/en/ to en.url.nl. so the non-www site. (and repeated for /it/, /pl/ etc etc.) Is that possible? Do you have any smart ideas on how to handle this?
If your URL structure is always the same and follows https://{hostname}/{locale}/path logic, you can do this with a single redirect rule using wildcards: Create a redirect rule in the dashboard · Cloudflare Rules docs. For example: Filter: (http.request.full_uri wildcard "https://italricambi.nl/*/*") or (http.request.full_uri wildcard "https://www.italricambi.nl/*/*") Then… > Dynamic > Expression: wildcard_replace(http.request.full_uri, "https://*italricambi.nl/*/*", "https://${2}.italricambi.nl/${3}")
Alternatively, if you’d like to use a simplified wildcard pattern view instead, you can achieve this with two redirect rules: Request URL : https://italricambi.nl/*/* for your first rule and https://www.italricambi.nl/*/* for your second one Then… > Target URL: https://${1}.italricambi.nl/${2} for both rules