Forum Discussion
Silicon_84874
Nimbostratus
Jul 13, 2010Redirection to the same pool
Hi,
I'm new to iRules and do not have any formal training and I'm looking for some assistance please.
This is what I'm trying to achieve;
I have 1 pool consisting of two servers.
The two servers/pool hosts 3 websites. For simplicity, lets call it a, b and c.
pool_1/a
pool_1/b
pool_1/c
What I'm hoping to achieve is this;
http://a.domain.com/ gets redirected to pool_1/a
http://b.domain.com/ gets redirected to pool_1/b
http://c.domain.com/ gets redirected to pool_1/c
So far this is what I managed to come up with. It's incomplete and possible not going to work, but if someone could please finish off where I started or suggest otherwise.
when HTTP_REQUEST {
if { [HTTP::uri] starts_with "a" } {
pool pool_1
} elseif { [HTTP::uri] starts_with "b" } {
pool pool_1
} elseif { [HTTP::uri] starts_with "c" } {
pool pool_1
}
}
Thanks in advance!
- hoolio
Cirrostratus
You could create a separate pool for each host header value and then use HTTP classes to select the corresponding pool. Or if you wanted to use an iRule you could use something like this:when HTTP_REQUEST { Check the requested host header set to lower case with wildcard matching switch -glob [string tolower [HTTP::host]] { "a.example.com" { pool pool_a } "b.example.com" { pool pool_b } "c.example.com" { pool pool_c } default { pool default_pool } } }
- Silicon_84874
Nimbostratus
Hi Aaron, - hoolio
Cirrostratus
Do you want the client to see the change? If so, you could send them an HTTP redirect. If you want to rewrite the Host and URI, you could do that as well using HTTP::header replace Host "newhost" and/or HTTP::uri.when HTTP_REQUEST { Check the requested host header set to lower case with wildcard matching switch -glob [string tolower [HTTP::host]] { "a.example.com" - "b.example.com" - "c.example.com" { Redirect the client to a hardcoded URL with the first field of the requested host header appended to the URI HTTP::redirect "http://www.example.com/[getfield [HTTP::host] " " 1]" } } }
when HTTP_REQUEST { Check the requested host header set to lower case with wildcard matching switch -glob [string tolower [HTTP::host]] { "a.example.com" - "b.example.com" - "c.example.com" { Rewrite the URI with the first field of the requested host header appended to the URI and hardcode the Host HTTP::header replace Host "www.example.com" HTTP::uri "/[getfield [HTTP::host] " " 1]" } } }
- Silicon_84874
Nimbostratus
Thanks Aaron! You've pointed me in the right direction. I had problems getting your direct examples to work for my situation. I did however manage to use your script to get there. I probably should have been more specific and mentioned that it was for internal use only. It may have made a difference to your example? - Silicon_84874
Nimbostratus
when HTTP_REQUEST { Check the requested host header set to lower case with wildcard matching switch -glob [string tolower [HTTP::host]] { "a.example.com" { Redirect the client to a hardcoded URL with the first field of the requested host header appended to the URI HTTP::redirect "http://www.example.com/[getfield [HTTP::host] " " 1]" "b.example.com" { HTTP::redirect "http://www.example.com/[getfield [HTTP::host] " " 1]" "c.example.com" { HTTP::redirect "http://www.example.com/[getfield [HTTP::host] " " 1]" } } }
- hoolio
Cirrostratus
I think the forum code munged your post. - Silicon_84874
Nimbostratus
Hi Aaron,
Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects