Forum Discussion

newmedia_129255's avatar
newmedia_129255
Icon for Nimbostratus rankNimbostratus
Jul 18, 2013

Help with irules redirect

Thanks in advance. The first irule works but the last one with the / appears not to be working and I was told that I need a uri. Can you please examine and let me know if the most effiecient way of doing the Irule

 

Here is the irule:

 

 

 

 

when HTTP_REQUEST {

 

log local0. "Requested hostname is: [HTTP::host]"

 

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

 

 

"*mywebsite1*" {

 

HTTP::respond 302 Location ""

 

}

 

"*mywebsite3.website.com/public*" {

 

HTTP::respond 302 Location "http://mywebsite4.com/public"

 

}

 

default { pool Web_Servers }

 

}

 

}

 

 

 

Thanks,

 

 

Michael

 

3 Replies

  • You are switching on the incoming host, not the URI, so you will never match "*mywebsite3.website.com/public*" you could match on "*mywebsite3.website.com" though. you do not want '*' at the end of the host options.
  • Hi Brian, what I"m looking for is when the users types mywebsite.website.com/public I want to do a 302 redirect to http://mywebsite.website4.com/public and when they type & mywebsite.website.com/public2 I want to do a 302 redirect to http://mywebsite.website4.com/public2. Will this syntax work:

     

     

    "*mywebsite.website.com*" {

     

    if { ([string tolower [HTTP::uri]] contains "public") } {

     

    HTTP::respond 302 Location "http://mywebsite.website4.com/public" }

     

    elseif { ([string tolower [HTTP::uri]] contains "public2") } {

     

    HTTP::respond 302 Location "http://mywebsite.website4.com/pubilc2" } }
  • bwolmarans_1284's avatar
    bwolmarans_1284
    Historic F5 Account
    Hi NewMedia,

     

     

    I don't have much time to reply, so this is "sub-optimal" as they say but this will work:

     

     

    when HTTP_REQUEST {

     

    log local0. "Requested uri is: [HTTP::uri] "

     

    if { [string tolower [HTTP::uri]] starts_with "/public2" } {

     

    HTTP::respond 302 Location "http://mywebsite.website4.com/public2"

     

    } elseif { [string tolower [HTTP::uri]] starts_with "/public" } {

     

    HTTP::respond 302 Location "http://mywebsite.website4.com/pubilc"

     

    } else {

     

    pool Web_Servers

     

    }

     

    }

     

     

    There is a better way, I'm sure, but I don't have time right now. But that will work for now.