Forum Discussion

muzammil_88686's avatar
muzammil_88686
Icon for Nimbostratus rankNimbostratus
Aug 15, 2011

Redirection to another pool

Dear Dev Team,

 

 

We have two Virtual Servers as below.

 

 

Virtual Server1:

 

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

 

 

Virtual Server Name: VS1

 

Virtual Server IP: 10.1.1.1

 

Pool Name: PL1

 

Nodes: 192.168.1.1 and 192.168.1.2

 

URL: www.xyz.com.us

 

 

Virtual Server2:

 

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

 

 

Virtual Server Name: VS2

 

Virtual Server IP: 10.1.1.2

 

Pool Name: PL2

 

Nodes: 192.168.1.3 and 192.168.1.4

 

URL: abc.xyz.com.us

 

 

I would like to redirect the URL: www.xyz.com.us/test123 to pool PL2 Servers as www.xyz.com.us/test123/test.html. I m using the iRule as below.

 

 

 

when HTTP_REQUEST priority 10 {

 

Check requested content on the header

 

if {[HTTP::uri] contains "test123"}{

 

log local0. "test123 detected"

 

HTTP Redirection

 

HTTP::redirect http://www.xyz.com.us/test123/test.html

 

Send to the new pool

 

pool PL2

 

}

 

}

 

 

It seems this is not working properly. When first time user tries he is getting the page but when he refreshes it is not working properly. Sometimes it is not working at all.

 

 

Could you pls help me out on this?

 

 

Appriciate your help!

 

4 Replies

  • Hi muzammil,

    You have an HTTP::redirect prior to your Pool Selection so it was getting redirected to away instead of being routed to the pool.

    If you want to maintain your HTTP::host value but still route your traffic to a different pool you can.

    Below I corrected the HTTP::uri to "/test123/test.html" only as a precaution (if the test.html is not the default document and to insure that you get directed to the right place). This is not necessarily needed depending on your application.

    I then just routed the traffic to the correct pool without a redirect.

     
    when HTTP_REQUEST priority 10 {
     Check requested content on the header
    if {[string tolower [HTTP::uri]] starts_with "/test123"}{
    Set new HTTP::uri
    HTTP::uri "/test123/test.html"
     Send to the new pool
    pool PL2
    }
    }
    

    Hope this helps.
  •  

    Now I m able to redirect to the new pool, but I see that in the browser the URL is showing as http://www.xyz.com.us/test123 instead of http://www.xyz.com.us/test123/test.html
  • Hi muzammil,

    After looking at what I gave you I have to apologize. The iRule that I gave you previously has the serious possibility of creating an endless loop and preventing proper site navigation.

    Anything that began with “/test123” would get redirected, so on the target page you could have gone to “/test123/test1.html” and you would have gotten sent back to “/test123/test.html”.

    The reason that the URI remained as “/test123” instead of “/test123/test.html” is because of this line:

    HTTP::uri "/test123/test.html"

    This caused the URI to be masked at the client (remain as “/test123” in the browser), but the Server received the modified URI.

    This iRule will route the traffic for any URI starting with “/test123” to the proper pool, but will not handle the URI modification / redirect. I would suggest making the target a default document. Any additional logic could prevent you from having other documents in the same folder without being modified (not to say that it is not possible, I am sure that it is, but you would have to build in another layer of logic to handle it).

     
    when HTTP_REQUEST {
    switch -glob [string tolower [HTTP::uri]] {
    "/test123*" { pool PL2 }
    }
    }
    
  • Colin_Walker_12's avatar
    Colin_Walker_12
    Historic F5 Account
    You could also do something like:

    
    when HTTP_REQUEST {
      if {([HTTP::path] starts with "/test123") && !([HTTP::uri] ne "/test123/test.html") } {
        HTTP::uri "test123/test.html"
        pool PL2
      }
    }
    

    Something like that should get you started, but as Michael said you are limiting the possible pages within the test123 directory to only that one specific page.

    Colin