Forum Discussion

Dave_22257's avatar
Dave_22257
Icon for Nimbostratus rankNimbostratus
Oct 25, 2011

URL Redirect

I need to create an irule to redirect certain URI strings to a specific pool on my F5 device. Sound simple enough but I am having issues writing the irule to match the specific URI's.

 

 

The uri's are as follows...

 

https://xyz.net.au

 

https://xyz.net.au:8181/webex or

 

https://xyz.net.au:8443/webex

 

 

 

The iRule I created and is failing is as follows...

 

 

 

when HTTP_REQUEST {

 

switch -glob [HTTP::host] {

 

"xyz.net.au {

 

switch -glob [HTTP::uri] {

 

":8181/*" { use pool Port_XYZ_8181 }

 

":8443/*" { use pool Port_XYZ_8443 }

 

default { use pool Pool_XYZ }

 

}}}}

 

 

 

When broswing to https://xyz.net.au, the web data is redirect and the web page is displayed. When trying xyz.nbet.au:8181/webex the redirect fails. I suspect the irule does not match the :8181/*

 

How can I write this irule to meet my needs?

 

Please help.

 

 

5 Replies

  • i understand port number e.g. 8181, 8443 is not in HTTP::uri. it is in HTTP::host.

     

     

    by the way, is virtual server listening on any port?
  • [root@iris:Active] config  b virtual bar list
    bvirtual bar {
       translate service enable
       snat automap
       pool foo
       destination 172.28.17.33:any
       ip protocol tcp
       rules myrule
       profiles {
          http {}
          tcp {}
       }
    }
    [root@iris:Active] config  b rule myrule list
    rule myrule {
       when HTTP_REQUEST {
            if {[HTTP::host] contains "xyz.net.au"} {
                    switch [getfield [HTTP::host] ":" 2] {
                            "8181" {
                                    log local0. "8181"
                            }
                            "8443" {
                                    log local0. "8443"
                            }
                            default {
                                    log local0. "default"
                            }
                    }
            }
    }
    }
    
    [root@iris:Active] config  curl -I http://xyz.net.au/
    HTTP/1.1 200 OK
    Date: Mon, 24 Oct 2011 22:14:17 GMT
    Server: Apache/2.0.59 (rPath)
    Last-Modified: Sat, 11 Jun 2011 00:31:47 GMT
    ETag: "667a-67-cfb682c0"
    Accept-Ranges: bytes
    Content-Length: 103
    Vary: Accept-Encoding
    Set-Cookie: testcookie=helloworld
    Content-Type: text/html; charset=UTF-8
    
    Oct 25 15:04:03 local/tmm info tmm[4672]: Rule myrule : default
    
    [root@iris:Active] config 
    [root@iris:Active] config  curl -I http://xyz.net.au:8181/
    HTTP/1.1 200 OK
    Date: Mon, 24 Oct 2011 22:14:32 GMT
    Server: Apache/2.0.59 (rPath)
    Last-Modified: Sat, 11 Jun 2011 00:31:47 GMT
    ETag: "667a-67-cfb682c0"
    Accept-Ranges: bytes
    Content-Length: 103
    Vary: Accept-Encoding
    Set-Cookie: testcookie=helloworld
    Content-Type: text/html; charset=UTF-8
    
    Oct 25 15:04:17 local/tmm info tmm[4672]: Rule myrule : 8181
    
    [root@iris:Active] config  curl -I http://xyz.net.au:8443/
    HTTP/1.1 200 OK
    Date: Mon, 24 Oct 2011 22:14:45 GMT
    Server: Apache/2.0.59 (rPath)
    Last-Modified: Sat, 11 Jun 2011 00:31:47 GMT
    ETag: "667a-67-cfb682c0"
    Accept-Ranges: bytes
    Content-Length: 103
    Vary: Accept-Encoding
    Set-Cookie: testcookie=helloworld
    Content-Type: text/html; charset=UTF-8
    
    Oct 25 15:04:30 local/tmm info tmm[4672]: Rule myrule : 8443
    
    
  • understand port number e.g. 8181, 8443 is not in HTTP::uri. it is in HTTP::host.

     

    => This is correct, was a typo on my part

     

     

    by the way, is virtual server listening on any port?

     

    Yes, the VS is listening on the ports 8181 and 8443.

     

     

    I have been asked to redirect a different HTTP::Host which comes in on the same IP address but needs to redirect to a different pool, hence the need to redirect the HTTP::host to a specific pool accordingly.
  • Solution privided has been implemented and tested successfully...

     

     

    iRule is as follows now

     

     

     

    if {[HTTP::host] contains "xyz.com.au"} {

     

    switch [getfield [HTTP::host] ":" 2] {

     

    "8181" {

     

    pool Prod_XYZ_8181

     

    }

     

    "8443" {

     

    pool Prod_XYZ_8443

     

    }

     

    }

     

    }

     

    }