Forum Discussion

Jason_19901's avatar
Jason_19901
Icon for Nimbostratus rankNimbostratus
Jul 25, 2011

Validate iRule

when HTTP_REQUEST {

 

 

Check if host is abc.com

 

if {[string tolower [HTTP::host]] eq "abc.com"}{

 

 

Rewrite the URI to /irj

 

HTTP::uri "/irj"

 

}

 

}

 

else

 

{

 

check if host is xyz.com

 

if {[string tolower [HTTP::host]] eq "xyz.com}{

 

 

rewrite the uri to /irq

 

HTTP::uri "/irq"

 

}

 

}

 

 

 

 

I have really never used more than one url. I need to append the URI. I want to know if the 'else' is correct or is it 'else if'

 

2 Replies

  • can u try this?

     

     

    when HTTP_REQUEST {

     

    if {[string tolower [HTTP::host]] eq "abc.com"} {

     

    HTTP::uri "/irj"

     

    } elseif {[string tolower [HTTP::host]] eq "xyz.com"} {

     

    HTTP::uri "/irq"

     

    } else {

     

    do something

     

    }

     

    }

     

     

    or

     

     

    when HTTP_REQUEST {

     

    switch [string tolower [HTTP::host]] {

     

    "abc.com" {

     

    HTTP::uri "/irj"

     

    }

     

    "xyz.com" {

     

    HTTP::uri "/irq"

     

    }

     

    default {

     

    do something

     

    }

     

    }

     

    }

     

  • Colin_Walker_12's avatar
    Colin_Walker_12
    Historic F5 Account
    Keep in mind that your iRule as it's written will redirect all requests to a single URI. Just making sure that's what you want. ;)