Forum Discussion

Unixian_307588's avatar
Unixian_307588
Icon for Nimbostratus rankNimbostratus
Dec 07, 2018

Port 80 vip redirect to pools and https

Hi Guys,

 

I have the following challenge that I am trying to crack.

 

VS with ip x.x.x.x is listening to port 80 I have multiple uri (XYZ) that i want to direct to different pools. And also have multiple uri (A-B) that I want to redirect to https For this I think of the following iRule:

 

`Code
when HTTP_REQUEST { 
if { [HTTP::host] eq "x.local.com" } { pool Pool1 }
elseif { [HTTP::host] eq "y.local.com" } { pool Pool2 }
elseif { [HTTP::host] eq "z.local.com" } { pool Pool3 }
}
when HTTP_REQUEST {
   if { [HTTP::host] eq "a.local.com" }
   elseif { [HTTP::host] eq "b.local.com" }
   { HTTP::redirect "https://www.local.com"}
   }`

however I am not getting this setup to work. As it redirect any request just to https.

 

Thanks for the help.

 

  • Try this:

    when HTTP_REQUEST { 
        switch [string tolower [HTTP::host]] {
            "x.local.com" { pool Pool1 }
            "y.local.com" { pool Pool2 }
            "z.local.com" { pool Pool3 }
            "a.local.com" -
            "b.local.com" { HTTP::redirect "https://www.local.com" }
            default { HTTP::redirect "https://www.local.com" }
        }
    }