Forum Discussion

jdewing's avatar
jdewing
Icon for Cirrus rankCirrus
Nov 05, 2009

URI Redirection

I'm new to IRule. I need to write a IRule to redirect to a specific server in the pool based on the path.

 

 

For example, https://Server1.com/ExportData should redirect to https://192.168.1.10/ExportData. The virtual server is setup for load balancing with 3 servers. Only one server will have the ExportData. How can I redirect to the specific node?

 

 

Thanks in advance

 

9 Replies

  • If you want to redirect the client to a specific server then you could do the following

     
     when HTTP_REQUEST { 
       if { [HTTP::uri] eq "/ExportData" } { 
         HTTP::redirect "http://192.168.1.10/[HTTP::uri]" 
      } 
     } 
     

    I hope this helps

    CB

  • Thanks for the quick response.

     

     

    It did not worked..I'm getting page cannot be found, that is because it connected to the other server (Load Balance) that don't have the export directory. Only of the server in the LB scheme have the export directory.

     

     

    http://192.168.1.10 is the private IP address, so I think the F5 is connected to the server with private IP address; but not able to route back out to the public virtual ip address. I don't know if i'm making sense here.

     

     

     

    Is there anyway we can redirect based on the node or possible create a separate pool for it?

     

     

  • I misunderstood what you meant. If you mean forwarding to a specific node then you can do the following

     
      when HTTP_REQUEST {  
        if { [HTTP::uri] eq "/ExportData" } {  
          node 192.168.1.10 80 
       }  
      }  
     

    CB
  • No luck! We are using https. I tried changed it to 443, still no luck.
  • What about the following

     
      when HTTP_REQUEST {   
         if { [HTTP::uri] contains "ExportData" } {   
           node 192.168.1.10 443  
        }   
       }   
      
  • CB,

     

     

    Thanks for your help. You put me in the right direction. I got it working.. here what I did..

     

     

    ************************

     

    when HTTP_REQUEST {

     

    set uri [string tolower [HTTP::uri]]

     

    if { $uri contains "exportdata" } {

     

    pool Servers_Pool member 192.168.1.10 80

     

    }

     

    }

     

    *************************

     

     

     

    i used "string tolower" because of the case sensitive issues.

     

     

    Jamie

     

     

  • Do you want to check the path (HTTP::path) or the query string (HTTP::query) for the exportdata string? The path is the URI minus the query string.

    You could eliminate the intermediate variable, uri:

     
     when HTTP_REQUEST { 
      
        if { [string tolower [HTTP::uri]] contains "exportdata" } { 
           pool Servers_Pool member 192.168.1.10 80 
        } 
     }  
     

    Aaron
  • To add the elimination of a variable that Aaron stats will in the long run execute the code faster. In this case it's more or less for simplicity.

     

     

     

  • Thank Aaron & CB

     

     

    I eliminated the variable statement. It is working just the way I wants.

     

     

    Many thanks