Allan_66523
Dec 08, 2011Nimbostratus
redirect url to another pool
I would like to have 1 vip for about 50 virtual web nodes. I would like the irule to look at the url and direct it to the correct pool. Can someone help me with this?
Thanks
Thanks
when HTTP_REQUEST {
switch -glob {string tolower [HTTP::uri]] {
"test.xzy.com" { pool test_pool }
"hello.xzy.com" { pool hello_pool }
"data.xzy.com" {pool data_pool }
default { pool default_pool}
}
}
That looks good. Just change HTTP::uri to HTTP::host and replace the leading { with a [:
when HTTP_REQUEST {
switch [string tolower [HTTP::host]] {
"test.xzy.com" { pool test_pool }
"hello.xzy.com" { pool hello_pool }
"data.xzy.com" {pool data_pool }
default { pool default_pool}
}
}
Aaron
Thanks,
virtual wiki
http://devcentral.f5.com/wiki/iRules.virtual.ashx
when HTTP_REQUEST {
switch [string tolower [HTTP::host]] {
"test.xzy.com" { Virutal test_VIP }
"hello.xzy.com" { Virutal hello_VIP }
"data.xzy.com" {Virutal data_VIP }
default { Virutal default_VIP}
}
}
[root@ve1023:Active] config b virtual bar list
virtual bar {
destination 172.28.19.79:80
ip protocol 6
rules myrule
profiles {
http {}
tcp {}
}
}
[root@ve1023:Active] config b rule myrule list
rule myrule {
when HTTP_REQUEST {
switch [string tolower [HTTP::host]] {
"test.xyz.com" { virtual test_vip }
"hello.xyz.com" { virtual hello_vip }
"data.xyz.com" { virtual data_vip }
default { virtual default_vip }
}
}
}
[root@ve1023:Active] config b virtual test_vip list
virtual test_vip {
snat automap
pool foo1
destination 1.1.1.1:80
}
[root@ve1023:Active] config b pool foo1 list
pool foo1 {
members 200.200.200.101:80 {}
}
[root@ve1023:Active] config b virtual hello_vip list
virtual hello_vip {
snat automap
pool foo2
destination 2.2.2.2:80
}
[root@ve1023:Active] config b pool foo2 list
pool foo2 {
members 200.200.200.102:80 {}
}
[root@ve1023:Active] config b virtual data_vip list
virtual data_vip {
snat automap
pool foo3
destination 3.3.3.3:80
}
[root@ve1023:Active] config b pool foo3 list
pool foo3 {
members 200.200.200.111:80 {}
}
[root@ve1023:Active] config b virtual default_vip list
virtual default_vip {
snat automap
pool foo4
destination 4.4.4.4:80
}
[root@ve1023:Active] config b pool foo4 list
pool foo4 {
members 200.200.200.112:80 {}
}
[root@ve1023:Active] config curl -i http://test.xyz.com
HTTP/1.1 200 OK
Date: Mon, 12 Dec 2011 14:51:24 GMT
Server: Apache/2.2.3 (CentOS)
Last-Modified: Fri, 11 Nov 2011 14:48:14 GMT
ETag: "4183e4-3e-9c564780"
Accept-Ranges: bytes
Content-Length: 62
Connection: close
Content-Type: text/html; charset=UTF-8
This is 101 host.
[root@ve1023:Active] config curl -i http://hello.xyz.com
HTTP/1.1 200 OK
Date: Mon, 12 Dec 2011 14:49:51 GMT
Server: Apache/2.2.3 (CentOS)
Last-Modified: Tue, 08 Nov 2011 12:26:29 GMT
ETag: "4183f1-30-47e02740"
Accept-Ranges: bytes
Content-Length: 48
Connection: close
Content-Type: text/html; charset=UTF-8
This is 102 host.
[root@ve1023:Active] config curl -i http://data.xyz.com
HTTP/1.1 200 OK
Date: Mon, 12 Dec 2011 14:50:37 GMT
Server: Apache/2.2.3 (CentOS)
Last-Modified: Wed, 30 Nov 2011 05:42:33 GMT
ETag: "418416-30-33ce6440"
Accept-Ranges: bytes
Content-Length: 48
Connection: close
Content-Type: text/html; charset=UTF-8
This is 111 host.
[root@ve1023:Active] config curl -i http://other.xyz.com
HTTP/1.1 200 OK
Date: Mon, 12 Dec 2011 14:49:07 GMT
Server: Apache/2.2.3 (CentOS)
Last-Modified: Wed, 30 Nov 2011 05:53:38 GMT
ETag: "41841b-3e-5b717c80"
Accept-Ranges: bytes
Content-Length: 62
Connection: close
Content-Type: text/html; charset=UTF-8
This is 112 host.
URL is test.xyz.com/test/hello
HTTP::host is test.xyz.com
HTTP::uri is /test/hello
5-Minute iRules: What’s a URL?
http://devcentral.f5.com/weblogs/jason/archive/2010/09/29/5-minute-irules-whatrsquos-a-url.aspx
additionally, you are able to use glob-style matching in switch i.e. -glob.
iRules 101 - 04 - Switch by Joe
http://devcentral.f5.com/Tutorials/TechTips/tabid/63/articleType/ArticleView/articleId/129/iRules-101--04--Switch.aspx