Forum Discussion
iRule Rewrite Question
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"
}
}
}
}
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
