jonathan_west_2
Sep 26, 2016Nimbostratus
redirect based on uri with datagroup
I'm trying to write an irule that will extract parts of a uri, look it up in a few datagroups to find where to route to and wether an animal is valid and then insert the extracted uri into the http header. I've not had much luck with extracting the uri so I've tried using multiple datagroups but im stuck. I'm using version 11.
Eg:
192.168.1.2/monkey/v1.2/code/12345/*
will lookup in datagroup for code:
String 12345
Value 192.168.1.100
and another datagroup for animal:
string monkey string chimp string gibbon
and then redirect to 192.168.1.100 changing the uri to /monkey/v1.2/*
So far I've tried using class match, set and stringmatch but I'm not sure Im going in the right direction, any help gratefully received.
when HTTP_REQUEST {
if { [ class match [string tolower [HTTP::uri]] contains animal ] and [ class match [string tolower [HTTP::uri]] contains code ] } {
set original [HTTP::host]
set new [class match -value [string tolower [HTTP::uri]] contains code]
HTTP::host [string map "$original $new" [string tolower [HTTP::host]]]
HTTP::redirect "http://$new[HTTP::uri]" }
else {
drop }
}