Forum Discussion

Allen_Ingram_39's avatar
Allen_Ingram_39
Icon for Nimbostratus rankNimbostratus
Feb 27, 2007

Migrating Redirects from CSS with Irule

 

We are in the process of migrating various redirects to the F5 from our legacy CSS'es. They are about 20 independant redirects pointing to various IP's but all the redirects are a part of www.hsn.com.

 

 

I had thought we could change all the redirects to point to the www.hsn.com address and then assign an IRULE to the www.hsn.com Virtual server that sent them to the appropriate redirect within the site.

 

 

Would anyone have a script of what the irule would look like? Obviously overall it would be:

 

 

If

 

requested URL has "X" in the field, then go to 1

 

If

 

requested URL has "X" in the field, then go to 2

 

If

 

requested URL has "Z" in the field, then go to 3

 

Else

 

www.hsn.com

 

 

 

  • After reading the forums, I assume I could use a IRULE like:

     

     

    (The actual name of the incoming HTTP would be www.whentowatch.com)

     

     

    when HTTP_REQUEST {

     

    if {[HTTP::host] eq "www.whentowatch.com"} {

     

    HTTP::redirect "http://www.hsn.com/redirect.aspx?id=273511&afsrc=1"

     

    }

     

    }

     

     

    The question how would I put multiples? Any help would be appreciated.

     

     

    Thanks!
  • hoolio's avatar
    hoolio
    Icon for Cirrostratus rankCirrostratus
    If you have more than a couple of cases to check, you could use the switch command:

    
    when HTTP_REQUEST {
       switch -glob [string tolower [HTTP::host]] {
          *example.com -
          *site1.example.net -
          *site2* {
             HTTP::redirect "http://host1.example.com"
          }
          *site3* -
          *site4* {
             HTTP::redirect "http://host2.example.com"
          }
          default {
             HTTP::redirect "http://host3.example.com"
          }
       }
    }

    You can check the iRules wiki page for switch for details on this (Click here)

    If you want to debug this, you could add log statements and check the /var/log/ltm log file. Here's an example for logging:

    log local0. "client: [IP::client_addr] matched first switch case"

    Aaron
  • Marcus_Slawik_8's avatar
    Marcus_Slawik_8
    Historic F5 Account
    hi jaingram,

     

     

    did you succeed? which solution did you choose? If you have it running would you mind posting you iRule and share it with the community.

     

     

    schwiddy
  • I have read that switch statements are far faster in terms of parsing an execution than regular if/else/then statements.

     

     

    Haven't tried it yet, but plan to.

     

     

    -Wes