Forum Discussion

MikeM_44778's avatar
MikeM_44778
Icon for Nimbostratus rankNimbostratus
Feb 28, 2010

Multiple Redirect based on URI

Trying to create a single iRule to do the following:

 

 

http://website1/News/?search=1234 redirects to http://website2/News/?search=1234

 

http://website1/Tech/?search=1234 redirects to http://website2/Tech/?search=1234

 

http://website1/SportsPage/?search=1234 redirect to http://website2/SportsPage/?search=1234

 

 

but only do this if /News , /Tech , or /SportsPage is in the URI, all other requests should continue to the default pool. Requests should also maintain search variables from the initial client request

 

 

Is this possible? Thanks for the help!

4 Replies

  • HI M.Markee,

    The VIP address should have the default pool assigned to it

    The following iRule basically checks the HOST and then checks to see if contains either news, tech, OR sports in the URI. If it does detect it then redirect to website2, otherwise it will not redirect and ultimately reach the default pool that was assigned to the VIP.

     
     when HTTP_REQUEST { 
     if {[HTTP::host] eq "www.website1.com"} { 
     switch -glob [string tolower [HTTP::uri]] { 
     "*news*" - 
     "*tech*" - 
     "*sportspage*" { HTTP::redirect "http://website2.com/[HTTP::uri]"} 
     } 
     }  
     } 
     

    I hope this helps

    Bhattman

  • Thanks!

     

    Is there anyway to keep case-sensitive URI intact and also go to different sites based on URI, for example:

     

     

    when HTTP_REQUEST {

     

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

     

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

     

    "/News*" { HTTP::redirect "http://website3.com/[HTTP::uri]"}

     

    "*tech*" -

     

    "/SportsPage*" { HTTP::redirect "http://website2.com/[HTTP::uri]"}

     

    }

     

    }

     

    }

     

  • sure...

     
     when HTTP_REQUEST {  
      if {[HTTP::host] eq "www.website1.com"} {  
      switch -glob [HTTP::uri] {  
      "*News*" -  
      "*Tech*" -  
      "*SportsPage*" { HTTP::redirect "http://website2.com/[HTTP::uri]"}  
      }  
      }   
      }  
     
  • As the HTTP host header value must be evaluated without regard to case, it would make sense to set the host value to lower case. If you need to check the case for the URI, you can leave the URI unchanged for the evaluation:

     
     when HTTP_REQUEST { 
        if {[string tolower [HTTP::host]] eq "www.website1.com"} { 
           switch -glob [HTTP::uri] { 
              "*News*" - 
              "*Tech*" - 
              "*SportsPage*" { HTTP::redirect "http://website2.com/[HTTP::uri]" } 
           } 
        } 
     } 
     

    Aaron