I think the general problem you're having is that you're trying to redirect on URI but only evaluating the host value. I see three possible options here:
-
Create two separate data groups - one for URI paths and one for host values
ltm data-group internal myhosts {
records {
domain1.de {
data domain.com
}
domain2.de {
data domain.com
}
}
type string
}
ltm data-group internal myuris {
records {
/ {
data /de-de
}
/careers {
data /de-de/careers
}
}
type string
}
when HTTP_REQUEST {
set myhost [class match -value [string tolower [HTTP::host]] equals myhosts]
set myuri [class match -value [string tolower [HTTP::uri]] starts_with myuris]
set redirect 0
if { $myhost ne "" } {
set redirect 1
} else {
set myhost [HTTP::host]
}
if { $myuri ne "" } {
set redirect 1
} else {
set myuri [HTTP::uri]
}
if { $redirect } {
HTTP::redirect "http://${myhost}${myuri}"
}
}
-
Create a single data group that incorporates host and URI
ltm data-group internal mypaths {
records {
domain1.de/ {
data domain.com/de-de
}
domain1.de/careers {
data domain.com/de-de/careers
}
}
type string
}
when HTTP_REQUEST {
set mypath [class match -value [string tolower [HTTP::host][HTTP::uri]] starts_with mypaths]
if { $mypath ne "" } {
HTTP::redirect "http://$mypath"
}
}
-
Assuming the host is only going to change between a very small set of values, just build a data group for URIs
when HTTP_REQUEST {
switch [string tolower [HTTP::host]] {
"domain1.de" -
"domain2.de" {
HTTP::redirect "http://domain.com[HTTP::uri]"
}
}
set myuri [class match -value [string tolower [HTTP::uri]] starts_with myuris]
if { $myuri ne "" } {
HTTP::redirect "http://[HTTP::host]${myuri}"
}
}
Arguably I think the third option would be the easiest to manage, with option 2 being the most difficult.