Forum Discussion
iRule Rewrite Question
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.
from: https://devcentral.f5.com/articles/name-based-virtual-hosting-with-ltm.Unfi8eLjWW5
when HTTP_REQUEST {
switch -glob [string tolower [HTTP::host]] {
marvel.somedomain.net { pool EXT_marvel.somedomain.net_https_pool }
default { reject }
}
}
2 Replies
- VFB
Cirrus
You'd have to write iRules with 301 redirects. for each domain - VernonWells
Employee
Do you want to use an explicit redirect (as
VFBmentions) 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
