Forum Discussion

IAmAJ_162542's avatar
IAmAJ_162542
Icon for Nimbostratus rankNimbostratus
Jul 25, 2018

Issues with Redirecting http request

Hi All,

I am having an issue with one of our configured irules. We're trying to redirect traffic sent to a specific url and it keeps failing.

when HTTP_REQUEST { Check if there aren't any active members in the default pool if { [active_members [LB::server pool]] < 1 } { set uri [HTTP::uri] switch -glob $uri { "/ftcdealerhome" - "/manual" { } }

log local0. "URI: [HTTP::uri]"
 }

switch -glob [string tolower [HTTP::uri]] { "/ftcdealerhome*" { HTTP::redirect http://[HTTP::host]:/newhistoryserver[HTTP::uri]&project=dealer&resource=portal }

   Traffic that reaching /ftcdealerhome should redirect to /newhistoryserver and another uri after. Any idea what it could be? 
  • Based on the following irule (with some fixed closed braces and formatting):

    when HTTP_REQUEST {  
       Check if there aren't any active members in the default pool   
      if { [active_members [LB::server pool]] < 1 } {   
        set uri [HTTP::uri]   
        switch -glob $uri {   
          "/ftcdealerhome" -   
          "/manual" {   
          }   
        }  
        log local0. "URI: [HTTP::uri]"  
     }  
      switch -glob [string tolower [HTTP::uri]] {   
        "/ftcdealerhome*" {   
            HTTP::redirect http://[HTTP::host]:/newhistoryserver[HTTP::uri]&project=dealer&resource=portal 
        }  
      }  
    }  
    

    This should work as follows:

     curl -v http://172.16.0.53/ftcdealerhome/test
    *   Trying 172.16.0.53...
    * TCP_NODELAY set
    * Connected to 172.16.0.53 (172.16.0.53) port 80 (0)
    > GET /ftcdealerhome/test HTTP/1.1
    > Host: 172.16.0.53
    > User-Agent: curl/7.60.0
    > Accept: */*
    >
    * HTTP 1.0, assume close after body
    < HTTP/1.0 302 Found
    < Location: http://172.16.0.53:/newhistoryserver/ftcdealerhome/test&project=dealer&resource=portal
    < Server: BigIP
    * HTTP/1.0 connection set to keep alive!
    < Connection: Keep-Alive
    < Content-Length: 0
    <
    * Connection 0 to host 172.16.0.53 left intact
    

    Note: your redirect switch statement is out of the "active pool member" if statement.