今天接到应用部门一个需求:
针对他们部门的某个URL: [url]http://www.abc.com/[/url][url]https://www.abc.com/[/url]访问,需要直接跳到某一台主机上,而不希望在这个pool成员中轮询。而且正常的访问这个URL,需要跳转到 [url]https://www.abc.com/[/url],但是一些程序针对这个域名的接口调用则不需要跳转,一般的接口调用的URL最后为“.do”。
这个需求比较奇怪,考虑到一般人访问这个域名都是直接访问[url]www.abc.com[/url] 其实就是 [url]http://www.abc.com/[/url],而程序接口调用则类似为 [url]http://www.abc.com/[/url]*****.do。这就可以区分开来,在F5的定义中HTTP::uri表示HTTP::host后面的部分。
HTTP::uri
  • Returns the URI of the request. It does not include the protocol (http or https) or hostname, just the path, starting with the slash after the hostname.
                           ------摘自 [url]http://devcentral.f5.com/wiki/default.aspx/iRules/HTTP__uri.html[/url]
 
所以在LTM上面写下如此irule:
[root@LB-1A-BIG6400:Active] root #b rule http_https_host1 list
rule http_https_host1 {
when HTTP_REQUEST {
if { [HTTP::uri] equals "/" } {
HTTP::redirect https://[HTTP::host][HTTP::uri]
}
elseif { [HTTP::uri] contains "host1" } {
HTTP::redirect https://[HTTP::host][HTTP::uri]
}
}
[root@LB-1A-BIG6400:Active] root # b rule redirect_host1 list
rule redirect_host1 {
when HTTP_REQUEST {
if { [HTTP::uri] ends_with "host1" } {
use node a.b.c.d 80
}
}
}
然后将http_https_host1用在80的virtual server上,而将redirect_host1用在443的virtual server上就ok了。
}