Forum Discussion

agidwani_102403's avatar
agidwani_102403
Icon for Nimbostratus rankNimbostratus
Feb 21, 2008

Need help

hello,

 

 

I need to accomplish the following

 

 

rewrite the uri https://aa.mycompany.com/compA/blah.acmx (can have companyA, Company123, CompanyABC etc)

 

 

rewrite the uri to https://aa.mycompany.com/global/blah.acmx

 

 

Note : we tried a simple redirect but receive HTTP 301 error and are stuck.

 

 

Any help would be highly appreciated.

 

 

 

Thanks - Arvind

 

8 Replies

  • Hi,

     

     

    you can create a data group with all the URI to replace and then do something like this.

     

     

    Let's say your datagroup's name is uri_to_replace (in this case you'll need to use only lowercase caracters in the datagroup i.e the string tolower)

     

     

    when HTTP_REQUEST {

     

    if {[matchclass [string tolower [HTTP::uri]] contains $::uri_to_replace] } {

     

    Do here your URI update here

     

    }

     

    }

     

     

     

    the second option is to use something like this:

     

     

    when HTTP_REQUEST {

     

    HTTP::uri [string map {find replace} [HTTP::uri]

     

    }

     

    }

     

     

     

    I tend to prefer the first one since then it's easier to maintain.
  • nmenant,

     

     

    Thank you for your help. I am not familiar with TCL, can you email me the exact syntax for find and replace ?

     

     

    Thank You - Arvind
  • Here's one option for companies "compA", "compB", and "compC". You can modify/expand this by replacing/adding new company names to the switch statement.

    when HTTP_REQUEST {
      switch -glob [HTTP::uri] {
        "/compA*" -
        "/compB*" -
        "/compC*" {
           set comp variable to first sub dir of in uri.
          set comp [getfield [HTTP::uri] "/" 2]
           perform a string map from the found string to "global" in the URI.
          set newuri [string map [list $comp "global"] [HTTP::uri]]
           Issue a HTTP redirect to the client browser
          HTTP::redirect $newuri
           Modify the URI sent to the backend server
           HTTP::uri $newuri
        }
      }
    }

    You have two options in changing the URI. You can issue a redirect to the client browser with the HTTP::redirect command. Or you can just modify the URI that is sent to the backend server. comment/uncomment the one that you desire.

    Now, if you have a large number of company names, you may want to move to a data group/matchclass solution. If that's the case, let me know and I'll work out an iRule for you.

    Hope this helps...

    -Joe
  • Hi,

     

     

    Picking this up...we are performing the URI rewrite successfully and hitting the backend server, but there response back is getting an error on the client application:

     

     

    Mapi Comm Base: Error during EndCall(): Destination Unreachable ---> WSE816: The header must match the value of an incoming message's HTTP Request Url if the soap receiver does not have an actor name. The header received contained "http://aa.mycompany.com/compA/file.asmx" while the HTTP Request Url was "http://aa.mycompany.com/global/file.asmx".

     

     

    How can we modify it so that the client is not aware of the change to the URI in the backend?

     

     

    We will also have a list of 200-300 companies to compare against so help on the best way to set that up is appreciated.

     

     

    Thanks,

     

    Brian

     

  • We need to create an iRule with very similar characteristics to the one you describe here... for many companies as well. Was there ever a discussion on the resolution to this effort?

     

     

    Thanks,

     

    Phil
  • Hi Phil,

    If you comment out the redirect and uncomment out the HTTP::uri command, then LTM will rewrite the URI before the request is sent to the pool. The client will not see the update as they aren't redirected to a new location.

     
            Issue a HTTP redirect to the client browser 
            HTTP::redirect $newuri 
      
            Modify the URI sent to the backend server 
           HTTP::uri $newuri 
     

    If you try that and run into any issues, let us know.

    Aaron
  • Okay, finally got the proper naming convention from management and the way they want to go!

     

     

    So what we're looking to do, is on two different levels. First, take the old URL of:

     

    www.companyX.domain.com and redirect to companyX.domain.com

     

    This should be a "simple" resolution I'm hoping!

     

     

    The second string is a little more difficult:

     

    hrp.companyX.domain.com and redirect to companyXhrp.domain.com

     

    So, you can see, that we're striping the "hrp" from the front and attaching it to the second string behind the company name.

     

     

    Any help on either of these cases would be MOST appreciated!!

     

     

    Thanks,

     

    Phil
  • This is what one of our internal programmers came up with. However, it doesn't work 100% of the time.

    when HTTP_REQUEST {  
     set header [HTTP::host] 
     set splitVals [split $header "."] 
     set urlPartCount [llength $splitVals] 
      
     if {$urlPartCount eq 4} { 
         set firstPart [string tolower [lindex $splitVals 0]] 
         switch $firstPart { 
     "hrp" 
     { 
     set splitVals [lreplace $splitVals 0 0] 
     lset splitVals 0 [lindex $splitVals 0]hrp 
     } 
     "www" 
         {  
         set splitVals [lreplace $splitVals 0 0] 
     } 
     } 
     set returnVal [join $splitVals "."] 
     HTTP::redirect "https://$returnVal" 
     } 
          
     }

    Any ideas???

    Thanks!

    Phil