Forum Discussion

Leonjsr_323498's avatar
Leonjsr_323498
Icon for Nimbostratus rankNimbostratus
Jun 09, 2017

iRule Question

Hi

 

I created an rule to send traffic to sub.domain.com to a particular node 1.1.1.1 and that works fine. But I need any other traffic either destined to the same domain name, domain.com to go to a different node 1.1.1.2 which may include the default webpage without host headers.

 

Is there a way to accomplish this? I checked around couldn't find an answer. Any example code appreciated.

 

Thanks

 

when HTTP_REQUEST {
if { [HTTP::header "Host"] starts_with "sub.domain.com"   } {
     snatpool SNAT
     node 1.1.1.1 80

} 
elseif { [HTTP::host] contains "domain.com"   } {
     snatpool SNAT
     node 1.1.1.2 80
}
}
  • Hello, I'm not sure when you haven't a host header, so Is this what your are trying to do?

    when HTTP_REQUEST {
        if { [getfield [HTTP::host] ":" 1] ends_with "sub.domain.com" } {
             snatpool SNAT
             node 1.1.1.1 80
        } 
        elseif { [HTTP::host] contains "domain.com" || [HTTP::path] contains "domain.com" } {
             snatpool SNAT
             node 1.1.1.2 80
        }
    }
    

    Test 1:

    GET /path1/page HTTP/1.1
    Host: www.sub.domain.com
    Connection: close
    

    Test 2:

    GET /path1/page HTTP/1.1
    Host: www.domain.com
    Connection: close
    

    Test 3:

    GET http://www.domain.com/path1/page HTTP/1.0
    

    Regards