Forum Discussion

Vijay_Krishnan_'s avatar
Vijay_Krishnan_
Icon for Nimbostratus rankNimbostratus
Dec 22, 2009

uri redirection to a virtual server

Hello Mates,

 

 

I am trying to create irule with uri mapping. I need to redirect to a virtual server based on the uri. Please see the commands below which I use. For some reason it does not seem to work. Can anyone of you help. It will be greatly appreciated.

 

 

 

when HTTP_REQUEST {

 

if {[HTTP::uri] contains "/shared/sso"} {HTTP::redirect "http://DAPPEXTVIP11"}

 

elseif {[HTTP::uri] contains "/cml/ccb"} {HTTP::redirect "http://DAPPEXTVIP1"}

 

}

9 Replies

  • Hi Vijay,

    First glance the synax looks fine. However, if you aren't receiving tcl errors then it's possible that you are not matching up on the URI or the webserver is not picking up the redirection.

    Try the following

      
      when HTTP_REQUEST {  
         log local0. "The following is the URI: [HTTP::URI]  
        switch -glob [string tolower [HTTP::uri]] {  
        "*shared/sso*" { HTTP::redirect "http://DAPPEXTVIP11/"}  
        "*cml/ccb*" { HTTP::redirect "http://DAPPEXTVIP1/" }  
        }  
      }  
      

    I hope this helps

    Bhattman

  • You might also try adding "string tolower" to Bhattman's suggestion to rule out case sensitive issues:

      
       when HTTP_REQUEST {   
          log local0. "The following is the URI: [HTTP::URI]   
         switch -glob [string tolower[HTTP::uri]] {   
         "*shared/sso*" { HTTP::redirect "http://DAPPEXTVIP11/"}   
         "*cml/ccb*" { HTTP::redirect "http://DAPPEXTVIP1/" }   
         }   
       }   
      
  • Thanks Naladar.

     

     

    Excellent pickup. I will include this statement during my iRules scripting.

     

     

    Vijay
  • I am having a syntax error..could you guys please help wih the following irule..thanks

     

     

     

    when HTTP_REQUEST {log local0. "The following is the URI: [HTTP::URI]

     

     

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

     

     

    "*services/TelephonyGatewayCheckSystemAvailable/1.0*" { HTTP::redirect "http://DAPPEXTVIP10-9906/"}

     

    "*services/TelephonyGatewayNotifyTopUpAccount/1.0*" { HTTP::redirect "http://DAPPEXTVIP10-9906/"}

     

    "*services/TelephonyGatewayNotifyBuyCLPPass/1.0*" { HTTP::redirect "http://DAPPEXTVIP10-9906/"}

     

    "*services/TelephonyGatewayNotifyGetPassCount/1.0*" { HTTP::redirect "http://DAPPEXTVIP10-9906/"}

     

    "*services/TelephonyGatewayNotifyLookupInvoice/1.0*" { HTTP::redirect "http://DAPPEXTVIP10-9906/"}

     

    "*services/TelephonyGatewayNotifyGetAccountBalance/1.0*" { HTTP::redirect "http://DAPPEXTVIP10-9906/"}

     

    "*services/TelephonyGatewayNotifyValidateLPN/1.0*" { HTTP::redirect "http://DAPPEXTVIP10-9906/"}

     

    "*services/TelephonyGatewayNotifyPayInvoice/1.0*" { HTTP::redirect "http://DAPPEXTVIP10-9906/"}

     

     

    }

     

    }
  • Hi Vijay,

    There's a missing close quote on the log statement. Also, since the action for all the cases is the same, you can combine them:

      
     when HTTP_REQUEST { 
      
        log local0. "The following is the URI: [HTTP::URI]" 
      
        switch -glob [string tolower [HTTP::uri]] { 
           "*services/TelephonyGatewayCheckSystemAvailable/1.0*" - 
           "*services/TelephonyGatewayNotifyTopUpAccount/1.0*" - 
           "*services/TelephonyGatewayNotifyBuyCLPPass/1.0*" - 
           "*services/TelephonyGatewayNotifyGetPassCount/1.0*" - 
           "*services/TelephonyGatewayNotifyLookupInvoice/1.0*" - 
           "*services/TelephonyGatewayNotifyGetAccountBalance/1.0*" - 
           "*services/TelephonyGatewayNotifyValidateLPN/1.0*" - 
           "*services/TelephonyGatewayNotifyPayInvoice/1.0*" { HTTP::redirect "http://DAPPEXTVIP10-9906/"} 
        } 
     } 
      

    Aaron
  • Thanks Aaron for your suggestion. Yes this has solved the problem of redirection. However I want to retain the original URL even after re-directing to the Virtual server, so that external parties do not see internal virtual server. In short I want the load balancer to proxy the connections. Any suggestions. Thanks.
  • Hi Vijay,

    One way you can do this is if you create a pool containing the virtual server. The iRule would look like the following:

     
      when HTTP_REQUEST {  
        
         log local0. "The following is the URI: [HTTP::URI]"  
        
         switch -glob [string tolower [HTTP::uri]] {  
            "*services/TelephonyGatewayCheckSystemAvailable/1.0*" -  
            "*services/TelephonyGatewayNotifyTopUpAccount/1.0*" -  
            "*services/TelephonyGatewayNotifyBuyCLPPass/1.0*" -  
            "*services/TelephonyGatewayNotifyGetPassCount/1.0*" -  
            "*services/TelephonyGatewayNotifyLookupInvoice/1.0*" -  
            "*services/TelephonyGatewayNotifyGetAccountBalance/1.0*" -  
            "*services/TelephonyGatewayNotifyValidateLPN/1.0*" -  
            "*services/TelephonyGatewayNotifyPayInvoice/1.0*" {  
                                                                  HTTP::header replace Host "DAPPEXTVIP10-9906" 
                                                                   Turn on SNAT if the client and virtual this irule is applied on is on the same side of the Interface on the LTM 
                                                                  snat automap 
         }  
      }  
       

    I hope this helps

    Bhattman
  •  

    Thanks Bhattman. This rule helped. However I found ProxyPass rule as suggested by another friend which did exactly the same and also allowed me add variables in Datagroup list. Thanks for you excellent support once again.
  • Hi Vijay

     

     

    Glad you found irule that gives you the expanded capability you were looking for.

     

     

    Bhattman