【问题标题】:How to redirect using F5 iRules with a variable in the URL如何使用 F5 iRules 和 URL 中的变量进行重定向
【发布时间】:2018-12-21 03:12:59
【问题描述】:

您好,我是 F5 iRule 的新手。

我正在尝试重定向 https://website1.com/userid=1234https://website2.com/userid=1234

这样,用户 ID 可能具有的任何值都将在重定向后保留。

我认为应该将 userid 值设置为一个变量。 有人可以分享使用什么代码吗?谢谢!

所以https://website1.com/userid=8888 应该转到https://website2.com/userid=8888 等等。

【问题讨论】:

    标签: 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]
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2020-09-01
      • 2020-02-14
      • 2016-05-30
      • 1970-01-01
      • 2018-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多