Forum Discussion

paulhaskew_7063's avatar
paulhaskew_7063
Icon for Nimbostratus rankNimbostratus
Jun 24, 2009

Rewrite portion of URI?

Hi everyone. First off this forum/website has been invaluable for finding information and answering my questions for quite some time. Wonderful!

So to my question, I have a particular site that we are accessing via http://sub.domain.com/culture/someservice/partners/?qs=*.

The problem I have is that the actual site lives on on http://sub.domain.com/culture/someservice.svc/partners/?qs=*.

The devs would like the flexability to be able to rewrite a portion of the URI dynamically when its requested from multiple cultures. The culture strings could be, en-US, en-GB, nl-NL, etc etc.

Here is the current iRule I wrote to simple just redirect the traffic based on what is contained within the URI, but how to setup the dynamic replace escapes me.

       
 when HTTP_REQUEST {       
 if {([string tolower [HTTP::uri]] contains "someservice") } {       
 pool my_secondary_pool       
 } else {       
 pool my_first_pool         
 }       
 log local0. "Request: [HTTP::uri]"          
 }        
 

I have looked at the stream command and tried HTTP::header but alas I admit defeat.

Any help would be greatly appricated.

6 Replies

  • To make sure I understand this: The BigIP will see a header named "URI" with a value like 'en-US' or 'en-GB', or with a value like 'syndicate.en-GB'?

     

     

    Are you looking to redirect to the appropriate service, or are you looking to dynamically change the URI as it the request is passed back to the server? Either is fine, I'm just trying to understand the flows and behaviors...

     

     

    Sorry if I am confused.

     

    -Matt
  • Matt,

     

     

    Thanks for the reply, and no worries on the confusion.

     

     

    What we are trying to do is dynamically replace the word someservice with someservice.svc in the URI string. The reason for the replace on the load balancer is so that its transparent to the end user and what is shown in the browser never changes.
  • Gotcha. So how do I know what service a user is coming from? Are you using the Accept-Language header to determine the ultimate service destination?

     

    -Matt
  • Not entirely sure how the devs are doing the culture work, that portion is coded in C and using II6. The culture request could change at any time really. Is there a way to deal with that start and ending portion of the URI with a wild card?
  • What we are trying to do is dynamically replace the word someservice with someservice.svc in the URI string.

    To literally do that you can use string map:

      
     when HTTP_REQUEST {  
         Replace someservice with someservice.svc in the path of the request.  Leave everything else in the path intact.  
        HTTP::path [string map -nocase {someservice someservice.svc} [HTTP::path]]  
        log local0. "[IP::client_addr]:[TCP::client_port]: Rewrote [HTTP::path] to\ 
           [string map -nocase {someservice someservice.svc} [HTTP::path]]"  
     }  
     

    If you don't expect the someservice string to be in a majority of requests, you could first check to see if the path contains someservice before trying to rewrite it with HTTP::path.

    Aaron
  • rock on, thanks man, I will give this a go. :D

     

     

    /EDIT

     

     

    Works fantastic, thank you very much, I wrapped it into my existing rule so the if statement applies. You guys ROCK!