Forum Discussion

muzammil_88686's avatar
muzammil_88686
Icon for Nimbostratus rankNimbostratus
Jul 01, 2012

Redirecting to a pool

I m having a problem with an iRule.

 

 

I m trying to redirect the below "Source" URL to "Destination" URL(NOTE: Here * could be any sub URI)

 

 

Source:

 

=====

 

http://www.XYZ.com/123/*

 

 

Destination:

 

==========

 

http://hello.XYZ.com:9090/*

 

 

Below is the iRule which I m trying, but unfortunately it is not working.

 

 

when HTTP_REQUEST priority 10 {

 

switch -glob [HTTP::path] {

 

"/stproxy*" { pool hello_9090_Pool }

 

}

 

}

 

 

 

Can anyone help on this?

 

 

Best Regards,

5 Replies

  • I m sorry, the actual iRule which I m using is as below

     

     

    when HTTP_REQUEST priority 10 {

     

    switch -glob [HTTP::path] {

     

    "/123*" { pool hello_9090_Pool }

     

    }

     

    }

     

  • e.g.

    [root@ve10:Active] config  b virtual bar list
    virtual bar {
       destination 172.28.19.79:http
       ip protocol tcp
       rules myrule
       profiles {
          http {}
          tcp {}
       }
    }
    [root@ve10:Active] config  b rule myrule list
    rule myrule {
       when HTTP_REQUEST {
       if {[string tolower [HTTP::uri]] starts_with "/123/"} {
          HTTP::redirect "http://[string map {www hello} [HTTP::host]]:9090[HTTP::uri]"
       }
    }
    }
    
    [root@ve10:Active] config  curl -I http://www.XYZ.com/123/something
    HTTP/1.0 302 Found
    Location: http://hello.XYZ.com:9090/123/something
    Server: BigIP
    Connection: Keep-Alive
    Content-Length: 0
    
    
  • Are you looking to "redirect", or simply use the pool members which listen on a different port(9090)? If you do not want to redirect, but use the pool you have in your iRule, you may have to correctly set the Host header on all requests to hello.XYZ.com or configure the pool members to listen for requests for www.XYZ.com in your example. This would be the case if you are taking requests for www.XYZ.com and load balancing them to a pool of servers that are accepting connections only for Host header hello.XYZ.com

     

     

    Eric
  • sorry i forgot to remove /123 in redirection. this is the revised one.

    [root@ve10:Active] config  b rule myrule list
    rule myrule {
       when HTTP_REQUEST {
       if {[string tolower [HTTP::uri]] starts_with "/123/"} {
          HTTP::redirect "http://[string map {www hello} [HTTP::host]]:9090[string map {/123/ /} [HTTP::uri]]"
       }
    }
    }
    
    [root@ve10:Active] config  curl -I http://www.XYZ.com/123/something
    HTTP/1.0 302 Found
    Location: http://hello.XYZ.com:9090/something
    Server: BigIP
    Connection: Keep-Alive
    Content-Length: 0
    
  • and this is an example based on Eric's suggestion.

    [root@ve10:Active] config  b virtual bar list
    virtual bar {
       snat automap
       pool foo
       destination 172.28.19.79:http
       ip protocol tcp
       rules myrule
       profiles {
          http {}
          tcp {}
       }
    }
    [root@ve10:Active] config  b rule myrule list
    rule myrule {
       when HTTP_REQUEST {
       if {[string tolower [HTTP::uri]] starts_with "/123/"} {
          HTTP::header replace Host "[string map {www hello} [HTTP::host]]:9090"
          HTTP::uri [string map {/123/ /} [HTTP::uri]]
          pool hello_9090_Pool
       }
    }
    }
    [root@ve10:Active] config  b pool hello_9090_Pool list
    pool hello_9090_Pool {
       members 200.200.200.101:websm {}
    }
    
    [root@ve10:Active] config  ssldump -Aed -nni 0.0 port 80 or port 9090
    New TCP connection 1: 172.28.19.251(35477) <-> 172.28.19.79(80)
    1341155212.1407 (0.0011)  C>S
    ---------------------------------------------------------------
    HEAD /123/something HTTP/1.1
    User-Agent: curl/7.15.5 (i686-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
    Host: www.XYZ.com
    Accept: */*
    
    ---------------------------------------------------------------
    
    New TCP connection 2: 200.200.200.10(35477) <-> 200.200.200.101(9090)
    1341155212.1428 (0.0018)  C>S
    ---------------------------------------------------------------
    HEAD /something HTTP/1.1
    User-Agent: curl/7.15.5 (i686-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
    Host: hello.XYZ.com:9090
    Accept: */*
    
    ---------------------------------------------------------------