Forum Discussion

Vytautas_klior1's avatar
Vytautas_klior1
Icon for Nimbostratus rankNimbostratus
Mar 29, 2012

http response uri rewrite based on server IP

hi folks,

 

 

I need to insert string (f.e. "/a1") on http response uri from specific server IP. For example if http response comes from server ip 10.10.10.1 then insert "/a1" in URI. It should look like this - if response is www.host.com/temp/temp1 then it should became www.host.com/a1/temp/temp1.

 

I do not have F5 for testing purposes and I don`t have much experience with irules..

 

I think that this irule should look like this, please correct if I am wrong.

 

 

 

Thanks in advice

 

 

 

 

 

 

 

when HTTP_RESPONSE {

 

 

 

if {(([IP::addr [IP::client_addr] equals 10.10.10.1]) and !([HTTP::uri] starts_with "/a1") } {

 

HTTP::respond "[HTTP::header]/a1[HTTP::uri]"

 

}

 

}

 

 

 

4 Replies

  • Hi Vytautas,

    That looks close. HTTP::header returns the value of a supplied header name. I think you want to insert the host value. Or you could leave out the protocol and host and just redirect to a local URI. Also, you have an extra open parenthesis.

    
    when HTTP_REQUEST {
       if { ([IP::addr [IP::client_addr] equals  10.10.10.1]) and  !([HTTP::uri] starts_with "/a1") } { 
           Absolute URL redirect to http:// with the originally requested host
          HTTP::respond  "http://[HTTP::host]/a1[HTTP::uri]"
    
           Local URI redirect to http:// with the originally requested host
          HTTP::respond  "/a1[HTTP::uri]"
       }
    }
    

    Aaron
  • Aaron - thanks for reply.

     

     

    I will try to overview the whole situation and then maybe you could advise what should I do or use. I have two servers, NEW and OLD, NEW one is not ready to work and if client open browser and type www.host.com, this request is sent to NEW server by default, then NEW server redirects user to www.host.com /a1, and this request is sent to OLD server (I am matching URI /a1 to send to OLD server and using “string map /a1 /” to cut this “a1” , because OLD server need to get requests without “/a1”) I am using this “/a1” only for redirecting traffic to OLD server.

     

    Now why I think that I need to insert this “/a1” to response – if user is clicking on some buttons in OLD server, it can be redirected to some resources, for example www.host.com/resource1 and this request will be sent to NEW server by default because there is no “/a1” in request uri and I need somehow to prevent this . I am trying to achieve that after first redirect to OLD server user will always be sending requests to OLD server until it closes connection at all.

     

    Maybe have any other ideas how to do this?

     

  • Do you need to send some requests to the old server and some to the new? If so what is the logic you need to use to separate the requests?

     

     

    Or do you need to insert /a1 in requests sent to the new server?

     

     

    Aaron
  • Well, NEW server has to authenticate users, but database is not moved from OLD server yet. Programmers will move one user by one from OLD server to NEW but meanwhile all connection to www.host.com must be forwarded to NEW server (F5 match host and sends to pool “NEW server” ), if server cannot find right user in its database then NEW server responds to user with redirect to www.host.com/a1, and this requests on F5 is matched by URI “/a1” and sent to pool “OLD server “ where user database is full and then users are working with OLD server.

     

    Old server URL are the same as on NEW server, and I am inserting this “/a1” only in communication between user and F5 and purpose is to indicate if connection should be sent to NEW or OLD server. I believe that if user will click on some links inside OLD server the requests by F5 will be sent to NEW server because there will be no “/a1” in link and F5 will not match this URI . I need to ensure that redirected user to OLD server will always stick to this server until the end of session. This is why I think I need to insert “/a1” for all responses that are coming from specific IP – OLD server IP.

     

    Yes, it sound confusing … But I got this task to do and I really need advice how to implement this on F5 using irules.