Forum Discussion

AngryCat_52750's avatar
AngryCat_52750
Icon for Nimbostratus rankNimbostratus
Feb 28, 2013

Changing Hostnames and URIs

we are making a service call to an external vendor. We call - internal.apple.com/foo/bar/pear.svc and we make it vendor.example.com/foo/bar/pear.svc with a irule -

 

when HTTP_REQUEST {

 

HTTP::header replace Host "vendor.example.com"

 

}

 

Is there a way to make internal.apple.com/fruits to become vendor.example.com/foo/bar/pear.svc ???

 

  • There is, something like this will do exactly what you want (but won't modify other URIs, they must match exactly);

    
    when HTTP_REQUEST {
     HTTP::header replace Host "vendor.example.com"
     if { [string tolower [HTTP::uri]] equals "/fruits" } {
      [HTTP::uri] "/foo/bar/pear.svc" }
    }
    
  • i think the last HTTP::uri should not have brackets around.

    when HTTP_REQUEST {
       HTTP::header replace Host "vendor.example.com"
       if { [string tolower [HTTP::uri]] equals "/fruits" } {
          HTTP::uri "/foo/bar/pear.svc"
       }
    }
    
  • Guys. instead of an if for the URI portion, could i do this instead?

     
    switch -glob  [string tolower [HTTP::uri]] { 
        "/fruits" { HTTP::uri "/foo/bar/pear.svc" }
     }
    
  • Hi kulastone,

     

     

    You will need to add an "*" to the end of what you are comparing within a Switch Statement.

     

     

    Starts with: "/fruits*" { do something }

     

    Ends with: "*/fruits.html" { do something }

     

    Contains: "*/fruits*" { do something }