Forum Discussion

Dixit_18200's avatar
Dixit_18200
Icon for Nimbostratus rankNimbostratus
Feb 23, 2010

Help needed for irule issue

Hi,

 

 

I have setup two irules for http to https redirection

 

 

1st for redirecting the below websites

 

 

http://www.acbg.com/ucc

 

http://www.acbg.com/saleshub

 

http://www.acbg.com/cct

 

 

and the irule i have appiled for this is as below

 

 

when HTTP_REQUEST {

 

if {[HTTP::uri] ends_with "/ucc"} {

 

HTTP::redirect "https://microsite.accenture.com/ACBG/Solutions/UCandC/Pages/default.aspx"

 

}

 

elseif {[HTTP::uri] ends_with "/saleshub"} {

 

HTTP::redirect "https://microsite.accenture.com/ACBG/Pages/SalesHub.aspx"

 

}

 

elseif {[HTTP::uri] ends_with "/cct"} {

 

HTTP::redirect "https://microsite.accenture.com/ACBG/Solutions/CustomerContact/Pages/default.aspx"

 

}

 

}

 

 

2nd irule for redirecting below websites

 

 

http://www.acbg.com/saleshub/dc

 

http://www.acbg.com/saleshub/ins

 

http://www.acbg.com/saleshub/ucc

 

http://www.acbg.com/saleshub/cct

 

http://www.acbg.com/saleshub/os

 

 

 

when HTTP_REQUEST {

 

if {[HTTP::uri] ends_with "/saleshub/ucc"} {

 

HTTP::redirect "https://microsite.accenture.com/ACBG_SalesHub/solutions/Pages/Outsourcing.aspx"

 

}

 

elseif {[HTTP::uri] ends_with "/saleshub/cct"} {

 

HTTP::redirect "https://microsite.accenture.com/ACBG_SalesHub/solutions/Pages/CCT.aspx"

 

}

 

elseif {[HTTP::uri] ends_with "/saleshub/dc"} {

 

HTTP::redirect "https://microsite.accenture.com/ACBG_SalesHub/solutions/Pages/DataCenterSolutions.aspx"

 

}

 

elseif {[HTTP::uri] ends_with "/saleshub/ins"} {

 

HTTP::redirect "https://microsite.accenture.com/ACBG_SalesHub/solutions/Pages/InfrastructureSolutions.aspx"

 

}

 

elseif {[HTTP::uri] ends_with "/saleshub/os"} {

 

HTTP::redirect "https://microsite.accenture.com/ACBG_SalesHub/solutions/Pages/Outsourcing.aspx"

 

}

 

}

 

 

however for the below websites the irule is not working properly. When i remove the first irule the below redirection works perfecrtly. Please help

 

 

http://www.acbg.com/saleshub/ucc

 

http://www.acbg.com/saleshub/cct

 

 

6 Replies

  • Hamish's avatar
    Hamish
    Icon for Cirrocumulus rankCirrocumulus
    Is there anything else in the iRules? Or are they just a single event? Two iRules shoould both fire, one after tjhe other, unless the first has a discard, drop or event statement...

    Can you put a logline in the start of the event to indicate whether they're being called, and what the URI is

    (Oh. I'd probably re-write the iRules to do a lookup in a class rather than a whole lot of if/then/elseif's... It'll scale better. e.g. (I was going to write one, but the findclass wiki page has it as an example already)

     
     class URIredirects { 
       "/dir1/dir2/dir3/ http://somehost.somewhere.com/redirect_target.html" 
       "/dir4/dir5/dir6/ http://someotherhost.nowhere.com/redirect_target.html" 
     } 
      
     when HTTP_REQUEST { 
       set location [findclass [HTTP::uri] $::URIredirects " "] 
       if { $location ne "" } 
         HTTP::redirect $location  
       } 
     } 
     
  • I'd guess this is an issue with trying to send a redirect from both rules on the same request. /var/log/ltm should show a runtime TCl error about multiple redirect invocations. For example, http://www.acbg.com/saleshub/ucc is going to match the first iRule check for a URI ending with /ucc and the second iRule check for /saleshub/ucc.

    Hamish's suggestion of using a datagroup and the findclass command is a good one if you don't need to use wildcards. If you do need to use wildcards, you could use a switch statement instead of a datagroup and findclass or the if/elseif/else chain. It would be idea if you could combine the iRules into one to ensure that only one redirect is attempted per HTTP request.

     
     switch -glob [string tolower [HTTP::uri]] { 
        "*/saleshub/ucc" { 
           HTTP::redirect "https://microsite.accenture.com/ACBG_SalesHub/solutions/Pages/Outsourcing.aspx" 
        } 
        "*/ucc" { 
           HTTP::redirect "https://microsite.accenture.com/ACBG/Solutions/UCandC/Pages/default.aspx"  
        } 
        default { 
            Take some default action 
        } 
     } 
     

    No matter what though, you'll need to pick which matches you want take priority for each URI stem (/saleshub/ucc or /ucc, etc).

    Aaron
  • Hi Aaron/Hamish,

     

     

    Thanks for the reply.

     

     

    Getting the following error when trying to apply irule provided by Aaron

     

    01070151:3: Rule [Vanity-Sales] error:

     

    line 1: [command is not valid in the current scope] [switch -glob [string tolower [HTTP::uri]] {

     

    "*/saleshub/ucc"

     

    { HTTP::redirect "https://microsite.accenture.com/ACBG_SalesHub/solutions/Pages/Outsourcing.aspx" }

     

    "*/ucc"

     

    { HTTP::redirect "https://microsite.accenture.com/ACBG/Solutions/UCandC/Pages/default.aspx" }

     

    }]

     

    line 1: [command is not valid in the current scope] [string tolower [HTTP::uri]]

     

    line 1: [command is not valid in the current scope] [HTTP::uri]
  • Sorry, that was a code snippet. It would need to be in the HTTP_REQUEST event:

     

     

     
     when HTTP_REQUEST { 
      switch -glob [string tolower [HTTP::uri]] {  
         "*/saleshub/ucc" {  
            HTTP::redirect "https://microsite.accenture.com/ACBG_SalesHub/solutions/Pages/Outsourcing.aspx"  
         }  
         "*/ucc" {  
            HTTP::redirect "https://microsite.accenture.com/ACBG/Solutions/UCandC/Pages/default.aspx"   
         }  
         default {  
             Take some default action  
         }  
      }  
     } 
     

     

     

    Aaron
  • Hey Aaron,

     

     

    Can you plese let me know who i can combile two irules in to one? at present i have created two switch irules for /ucc and /cct can you please let me know how i can combine these two into one?
  • Just extend Aaron's example:

      
      when HTTP_REQUEST {  
       switch -glob [string tolower [HTTP::uri]] {   
          "*/saleshub/ucc" {   
             HTTP::redirect "https://microsite.accenture.com/ACBG_SalesHub/solutions/Pages/Outsourcing.aspx"   
          } 
          "*/saleshub/cct" { 
             HTTP::redirect "https://microsite.accenture.com/ACBG_SalesHub/solutions/Pages/CCT.aspx" 
          } 
          "*/ucc" {   
             HTTP::redirect "https://microsite.accenture.com/ACBG/Solutions/UCandC/Pages/default.aspx"    
          }   
          "*/cct" { 
             HTTP::redirect "https://microsite.accenture.com/ACBG/Solutions/CustomerContact/Pages/default.aspx" 
          } 
          default {   
              Take some default action   
          }   
       }   
      }  
      

    You just want to make sure your saleshub matches occur first in the switch so your matches occur correctly for /saleshub/*