Forum Discussion

yuanqiang_22112's avatar
yuanqiang_22112
Icon for Nimbostratus rankNimbostratus
May 09, 2016

irules for different pool

Hi please look this irules:

 

when HTTP_REQUEST { if { [HTTP::uri] contains "login" } { pool pc } elseif { [HTTP::uri] contains "hfs" } { pool pc2 } else { pool dns } } now I take a test---I input browser with "txhd.com/login",I have the anwser from pc pool , but if I input browser with "login.txhd.com" ,I gain the anwser from dns pool; How can gain user defined page according to my irulse when I input browser "login.txhd.com" or "hfs.txhd.com"? Please help me change the irules

 

2 Replies

  • You first have to understand all of the parts of a URL. So for example:

    http://www.domain.com/images/mycat.png?foo=bartest
    

    www.domain.com is the host, so that's accessible with the [HTTP::host] or [HTTP::header Host] command

    /images/mycat.png?foo=bar is the "URI", so that's accessible via the [HTTP::uri] command

    /images/mycat.png is the path, so that's accessible via the [HTTP::path] command

    ?foo=bar is the query, so that's accessible via [HTTP::query]

    So to answer your question, "login.txhd.com" isn't matching your [HTTP::uri] match because "login" isn't in the URI, it's in the Host.

  • Hi,

    • HTTP::uri only return URI part of the URL--> starting with the /
    • HTTP::host will return the Host part of the URL: login.txhd.com

    I recommend you to use switch instead of if / elseif / else

    when HTTP_REQUEST {
        switch -glob [HTTP::host] {
            "login*" {pool pc}
            "hfs.txhd.com" {pool pc2}
            default {pool dns}
        }
    }