Forum Discussion

mark_57891's avatar
mark_57891
Icon for Nimbostratus rankNimbostratus
Sep 16, 2009

Rewrite URLs question

Hello all. I'm trying to create an iRule to perform URI rewrite when a match is encountered. Essentially, I want to rewrite URL 1 into URL 2, where the wi_id=value will constantly change.

 

 

URL 1: http://myoriginalappserver/gopwfbasic?wi_id=935461&email=X

 

 

URL 2: http://mynewappserver/webdynpro/dispatcher/sap.com/zmobile/Zmobile?wi_id=935461&email=X

 

 

I need to grab the "wi_id=935461&email=X" string and use it to format new URLs. I have an iRule which, when the criteria is met (URI contains /gopwfbasic), uses string trim to capture the string and then replace the URL. However, it does not seem to be working as intended. Depending on the length of the requestURI, not all of the string is captured.

 

 

Does anyone have a recommendation / suggestion? Thanks,

 

 

------------

 

switch -glob [HTTP::uri] {

 

"/gopwfbasic?*" {

 

set requestURI "/gobwfbasic?"

 

 

}

 

"/gopwfcomplex?*" {

 

set requestURI "/gopwfcomplex?"

 

 

}

 

default {

 

log local0. "no match"

 

 

}

 

}

 

 

If the following variable exists (requestURI), then criteria has been met and the URL should be re-written

 

if {[info exists requestURI]}{

 

set trimURI [string trimleft [HTTP::uri] "$requestURI"]

 

log local0. "trimURI: $trimURI"

 

set newURI "mynewappserver/webdynpro/dispatcher/sap.com/zmobile/Zmobile?$trimURI"

 

log local0. "Client IP: [IP::client_addr]. Updated URI: http://$newURI"

 

HTTP::redirect "http://$newURI"

 

}

 

 

------------
  • How about the following:

     
     when HTTP_REQUEST { 
     if { [HTTP::query] starts_with "wi_id" } { 
     switch -glob [HTTP::uri] { 
     "/gopwfbasic?*" - 
     "/gopwfcomplex?*" { 
      set rewrite [substr [HTTP::query] 0 0] 
      http::redirect "http://mynewappserver/webdynpro/dispatcher/sap.com/zmobile/Zmobile?$rewrite" 
     } 
     } 
     } 
     } 
     

    I hope this helps

    CB

  • Hi Mark,

     

     

    Actually after looking at your question my code is a bit overstated. Here is a new code that will work as a better example

     

     

     
      when HTTP_REQUEST {  
      if { [HTTP::query] starts_with "wi_id" } {  
      switch -glob [HTTP::uri] {  
      "/gopwfbasic?*" -  
      "/gopwfcomplex?*" {  
       http::redirect "http://mynewappserver/webdynpro/dispatcher/sap.com/zmobile/Zmobile?[HTTP::query]"  
      }  
      }  
      }  
      }  
     

     

     

     

    CB

     

  • Thank you very much for your prompt responses. I have modified the iRule using your example and we are currently testing.
  • Great. Let us know how it goes. We would love to hear the results.

     

     

    CB

     

  • The iRule works exactly as intended. Thank you again for your assistance!
  • The iRule works exactly as intended. Thank you again for your assistance!
  • The iRule works exactly as intended. Thank you again for your assistance!