cancel
Showing results for 
Search instead for 
Did you mean: 
Login & Join the DevCentral Connects Group to watch the Recorded LiveStream (May 12) on Basic iControl Security - show notes included.

irule - converting if to switch

cwdusheke
Nimbostratus
Nimbostratus

I am trying to convert my irule from using the if to the switch. Here' s an email of my old irule.

 

when HTTP_REQUEST {

if { (([HTTP::host] contains "abc1.com") && ([HTTP::uri] == "/" )) }{

HTTP::uri "/tf/myPLAN/SponsorWelcome?cz=123456789"

}

elseif { (([HTTP::host] contains "abc2.com") && ([HTTP::uri] == "/" )) }{

HTTP::uri "/tf/myPLAN/SponsorWelcome?cz=223456789"

}

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

    HTTP::respond 301 Location "https://example11.com"

  }

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

    HTTP::respond 301 Location "https://example22.com"

  }

1 ACCEPTED SOLUTION

Hello.

 

Try this:

when HTTP_REQUEST { switch -glob [string tolower [HTTP::host]] { "*abc1.com" { if { [HTTP::uri] eq "/" } { HTTP::uri "/tf/myPLAN/SponsorWelcome?cz=123456789" } } "*abc2.com" { if { [HTTP::uri] eq "/" } { HTTP::uri "/tf/myPLAN/SponsorWelcome?cz=223456789" } } "*example1.com" { HTTP::respond 301 Location "https://example11.com" } "*example2.com" { HTTP::respond 301 Location "https://example22.com" } } }

KR,

Dario.

Regards,
Dario.

View solution in original post

3 REPLIES 3

Hello.

 

Try this:

when HTTP_REQUEST { switch -glob [string tolower [HTTP::host]] { "*abc1.com" { if { [HTTP::uri] eq "/" } { HTTP::uri "/tf/myPLAN/SponsorWelcome?cz=123456789" } } "*abc2.com" { if { [HTTP::uri] eq "/" } { HTTP::uri "/tf/myPLAN/SponsorWelcome?cz=223456789" } } "*example1.com" { HTTP::respond 301 Location "https://example11.com" } "*example2.com" { HTTP::respond 301 Location "https://example22.com" } } }

KR,

Dario.

Regards,
Dario.

cwdusheke
Nimbostratus
Nimbostratus

Thank you very much. I was looking through a lot of examples but not sure how to do it.

You're welcome 🙂

Please, don't forget to mark the answer as "the best" if it was helpful.

Regards,
Dario.