I’ve got a iRule that I would like to edit so that when I direct someone to marvel.somedomain.net pool it redirects to either kibana.somedomain.net or marvel.somedomain.net and appends the url with /app/kibana or /app/marvel depending on what site they are trying to reach. How would I go about this?
Both of these apps run off of the same port on the servers in the pool which is why I think I need a solution for this. If there is a better way to go about it I’m open to anything.
Do you want to use an explicit redirect (as ~~ @VFB ~~ mentions) or perform a transparent rewrite?
As usual, this is best controlled using a class match. I’ll assume there are two conditions: 1. change host to marvel… and set the request-uri to /app/marvel (you say append, and if that’s what you really mean, it’s possible, but does require some changes); or 2. change host to kibana… and set the request-uri to /app/kibana. I further assume that the decision is made based on the request host. So, I’ll create a data group (using an internal data-group here for illustration purposes) where each data group element key is the request hostname, and the value is either “marvel” or “kibana”:
ltm data-group internal dg-host-based-redirect {
records {
"foo.bar.com" { data "marvel" }
"bin.baz.net" { data "kibana" }
"ankle.feet.com" { data "marvel" }
}
type string
}
For explicit redirect (not tested!):
when RULE_INIT {
set static::hbr_data_group "dg-host-based-redirect"
}
when HTTP_REQUEST {
set m [class lookup [string tolower [HTTP::host]] $static::hbr_data_group]
if { $m ne "" } {
switch $m {
"marvel" {
HTTP::redirect "http://marvel.somedomain.com/app/marvel"
}
"kibana" {
HTTP::redirect "http://kibana.somedomain.com/app/kibana"
}
}
}
}
If you want to transparently change those (not tested!):
when RULE_INIT {
set static::hbr_data_group "dg-host-based-redirect"
}
when HTTP_REQUEST {
set m [class lookup [string tolower [HTTP::host]] $static::hbr_data_group]
if { $m ne "" } {
switch $m {
"marvel" {
HTTP::host "marvel.somedomain.com"
HTTP::uri "/app/marvel"
}
"kibana" {
HTTP::host "kibana.somedomain.com"
HTTP::uri "/app/kibana"
}
}
}
}