Forum Discussion

HG's avatar
HG
Icon for Cirrus rankCirrus
Oct 17, 2017

Irule help - redirect to another VS based on path

Hi all. I would like your help in order to proceed with the following.I would like to redirect traffic based on URI to another VS. For example:

Http://1.1.1.1:8000/test1/ok?wsl
Http://1.1.1.1:8000/test5/okok?rore
Http://1.1.1.1:8000/intern/testok?ok

to

Http://2.2.2.2:8000/test1/ok?wsl
Http://2.2.2.2:8000/test5/okok?rore
Http://2.2.2.2:8000/intern/testok?ok

I would like this to work only for those specific paths.I have in mind something like the irule below. Could you please advice ?

when HTTP_REQUEST
{
    set lowCaseURI [string tolower [HTTP::uri]]
    if {[HTTP::host] equals "1.1.1.1"}
    {
        switch -glob $lowCaseURI
        {
        "/test1/ok?wsl"
        "/test5/okok?rore"
        "/intern/testok?ok"
        { HTTP::redirect "http://2.2.2.2"}
        default
        {pool 1.1.1.1}
    }
    }

2 Replies

  • I would probably put all your URIs in a datagroup and use a second 'if' statement rather than a switch statement. This way you can add more URIs without changing the code. Also, if you just want to send traffic to another Virtual server, you can use the 'virtual' command rather than a redirect - unless a redirect is your requirement.

     

    If you set a default pool in in your virtual server, you don't need to specify it in the iRule.

     

    when HTTP_REQUEST {
        set lowCaseURI [string tolower [HTTP::uri]]
        if {[HTTP::host] equals "1.1.1.1"} {
            if {[class match $lowCaseURI starts_with your-uri-dg]} {
                virtual name-of-your-vs
            }
        }
    }
  • You don't need an iRule to do this. You can build it up all in the LTM Policies.

     

    Look for the URI path and then forward it back to the virtual server.

     

    Local Traffic > Policies