【问题标题】:How to redirect using F5 iRules with a variable in the URL如何使用 F5 iRules 和 URL 中的变量进行重定向
【发布时间】:2018-12-21 03:12:59
【问题描述】:
【问题讨论】:
标签:
url-redirection
big-ip
irule
【解决方案1】:
如果该模式是一致的,您就不需要变量。一个简单的规则是:
when HTTP_REQUEST {
if { [HTTP::host] eq "website1.com" } {
HTTP::redirect https://websitesite2.com[HTTP::uri]
}
}
但是,如果您使用的是 v11.4+,则确实应该为此使用本地流量策略,因为它作为 TMOS 的内置功能具有更高的性能。
ltm policy sample_site_redirect {
controls { forwarding }
last-modified 2018-12-20:09:33:02
requires { http }
rules {
full_uri_redirect {
actions {
0 {
http-reply
redirect
location tcl:https://website2.com[HTTP::uri]
}
}
conditions {
0 {
http-host
host
values { website1.com }
}
}
}
}
status published
strategy first-match
}
如果此规则或策略附加到的虚拟服务器的所有流量仅用于 website1,您可以消除这些条件。我不想假设。如果您只想匹配并重定向以 /user= 开头的 URI,您可以这样做:
when HTTP_REQUEST {
if { ([HTTP::host] eq "website1.com") && ([string tolower [HTTP::uri]] starts_with "/user=") } {
HTTP::redirect https://website2.com[HTTP::uri]
}
}