Forum Discussion

raytoles_75680's avatar
raytoles_75680
Icon for Nimbostratus rankNimbostratus
Jan 13, 2010

Several redirects in one iRule

I want to through this out there to see if any of the experts see any problems with this irule. We have some pretty specific redirects I want to place in a single iRule. Below is a sample of where I'm goint. There's about 15 different author names involved (authorx = author's name). The author's location on the oldsite must be redirected to the author's site location on the new site.

 
  when HTTP_REQUEST priority 499 {    
  
    if {[string tolower [HTTP::host]] equals "newsite.apa.org" and [string tolower [HTTP::uri]] starts_with "/newbooks/newresources" } { 
  
 set redirected 0 
  
     switch -glob [HTTP::uri] {    
  
    "/books/resources/author1" { 
  
 HTTP::redirect "http://oldsite.apa.org/oldbooks/oldsupp/author1" 
  
  
  
 } 
  
  "/books/resources/author2" { 
  
 HTTP::redirect "http://oldsite.apa.org/oldbooks/oldsupp/author2" 
  
  
  
 } 
  
 "/books/resources/author3" { 
  
 HTTP::redirect "http://oldsite.apa.org/oldbooks/oldsupp/author3" 
  
  
  
 } 
  
 "/books/resources/author4" { 
  
 HTTP::redirect "http://oldsite.apa.org/oldbooks/oldsupp/author4" 
  
  
  
 } 
  
       default {    
             
        log local0. "Redirect to New site author root"    
  
        HTTP::redirect "http://newsite.apa.org/newpubs/newbooks" 
  
  
  
                          }    
  
     }    
  
    }    
  
   } 
  
  
 

3 Replies

  • Hi Ray,

     

     

    You're doing a check on the host header value and the URI. But then you're doing a separate check of the URI with the switch statement. A URI couldn't match /newbooks/newresources and any of the specific switch cases so everything which matches the first check for /newbooks/newresources would hit the default switch case.

     

     

    If you're not using wildcards in the switch cases, you could remove the -glob flag from the switch statement.

     

     

    Also, I assume the author names are not literally author[1-x]? If they're unique names and you only want to redirect specific names to new author-specific locations, I'm not sure there is a way to trim down the number of switch cases. If the names were part of a general pattern, you might be able to replace the non-default switch cases with one case. Can you provide a few sample original URIs you want to redirect and their corresponding redirect locations using more exact names?

     

     

    Aaron
  • Here are a couple examples the author's actual name is used in the URIs.

     

     

    http://newsite.apa.org/xbooks/xresources/baruss

     

    should go to: http://oldsite.apa.org/xbooks/supp/baruss/

     

     

    http://newsite.apa.org/xbooks/xresources/dutytoprotect

     

    should go to: http://oldsite.apa.org/xbooks/supp/dutytoprotect/

     

     

    http://newsite.apa.org/xbooks/xresources/hill

     

    should to go: http://oldsite.apa.org/xbooks/supp/hill/

     

  • So can you just take anything after /xbooks/xresources/ and append that to a URL of http://oldsite.apa.org/xbooks/supp/ for the redirect? Or are there http://newsite.apa.org/xbooks/xresources/xyz URLs you don't want to redirect to http://oldsite.apa.org/xbooks/supp/xyz?

     

     

    Aaron