iRule Array with string map redirects not working
Hi,
I'm trying to create a iRule with arrays that sendt traffic to both pools and 302 redirection.
The iRule should behave like this:
The first array simply forwards traffic to a pool. It's working as intended.
The second array should redirects certain URI's to a different URL. It get's difficult when I also need to append some of the the URI to the redirect target.
Example:
Requests to https://bee.test.example.no/cfs/whatever should redirect to https://cfs-ws-customer.vendor.no/whatever
So I would like to remove "/cfs/" from the URI but append/keep the rest and add it to the redirect URL.
I've tried using string map, but I can's seem to get it to work.
More examples:
Requets to bee.test.example.no/caf/whatever/example should redirect to https://banktest.portal.no/dummy-text_to_show-something-web/whatever/example
Requets to bank.test.example.no/insurance/whatever/dummy should redirect to http://test.dummy.customer.no/example/whatever/dummy.
Requets to redaktor-*.test.example.no/cfs/example/stuff should redirect to https://cfs-ws-customer.vendor.no/example/stuff
I would appreciate any help or tips! Let me know if something is unclear 🙂
`when HTTP_REQUEST {
array set pools {
sliders.test.example.no pool_example_test
bee.test.example.no pool_example_test
tinypower.test.example.no pool_example_test
tbank.test.example.no pool_example_test
bank.test.example.no pool_example_test
womvalley.test.example.no pool_example_test
redakto- pool_example_redaktor
priceapi1-sitecore1.test.example.no pool_example_redaktor
}
array set redirects {
/caf https://banktest.portal.no/dummy-text_to_show-something-web/
/insurance http://test.dummy.customer.no/example/
/cfs https://cfs-ws-customer.vendor.no/
}
foreach {web_uri new_destination} [array get redirects] {
if { [string tolower [HTTP::uri]] starts_with "$web_uri" } {
HTTP::respond 302 noserver Location "$new_destination[string map {$web_uri [HTTP::uri]} [HTTP::uri]]"
return
}
}
foreach {host_header member_pool} [array get pools] {
if { ([string tolower [HTTP::host]] equals $host_header) }{
pool $member_pool
return
}
elseif { ([string tolower [HTTP::host]] starts_with $host_header) }{
pool $member_pool
return
}
}
HTTP::respond 200 Content "This site does not exist"
}`