I’m trying to create a Redirect rule to take any inbound URIs that include “/guidebook/type1”, and redirect them to a new, parameterised URL using a new prefix.
I believe I’ve written a meaningful regex_replace function, but I"m new to regex, and I can’t seem to get the rule to save, so I’m unsure if I’m doing something wrong. The domain in question is on a business plan (which I read should mean regex are available in rules.)
For example, I’m trying to redirect THIS: example.com/new-york/en-us/guidebook/type1
To THIS: prefix.example.com/guidebook?destination=new-york&language=EN&passType=TYPE1&brand=BRAND1
The regex I’ve drafted is this: regex_replace(http.request.uri.path,"([\w-]+)\/(\w{2})-\w{2}\/guidebook\/type1","https://prefix.example.com?destination=${1}&language=${2}&passType=TYPE1&brand=BRAND1"
The option to save a draft or deploy are inactive, which feels like there’s some kind of in-page validation that’s rejecting my rule. Is my replacement function is incorrectly formed, or is there something else that could be blocking me from saving / applying the redirect rule?
Hmmm… it looks like I might actually be missing edit access to redirect rules. Would still appreciate any feedback on My First Regex , and will confirm as soon as I’ve unravelled the permissions issue (I feel pretty silly for assuming those permissions were all in place!)
You could make use of concat() to render the dynamic URL expression easier to read. Start the old path regex with the ^ caret to make the match less ambiguous: You do not need to escape forward slashes.
Assuming you want to match and capture “new-york” or variations that may have one or more hyphenated words, you’d need to double escape both w and - inside the []. So:
"([\\w\\-]+)/(\\w{2})-\\w{2}/guidebook/type1"
As for the new path and query, since we already concatenated the hostname, you need only to insert a / to replace the original slash from the path:
I hope it works, but as with any regex, please test, test, then test again with multiple variations of input URL to make sure this won’t unintentionally break something.