Forum Discussion

AshuA_246482's avatar
AshuA_246482
Icon for Nimbostratus rankNimbostratus
Nov 27, 2017

Redirect the traffic based on uri

Hi I have to create a i-rule for a request mentioned below. The users will be using the same URL, but different URIs and should be redirected to different ports and URIs on the servers. I have tried to write the code and logic. Can someone please check and confirm it the logic and syntax is correct ?

 

when HTTP_REQUEST { if { [HTTP::uri] contains "/abc/efg/Contract" } { node 172.27.117.68 89 } elseif { [HTTP::uri] contains "/xyz_QuotationService" } { node 172.27.117.68 99 } default { pool pool_default } }

 

  • Your iRule is generally OK, it should look like this (alternatively you could use switch statement):

     

    Code

    when HTTP_REQUEST { if { [HTTP::uri] contains "/abc/efg/Contract" } { node 172.27.117.68 89 }

     

    elseif { [HTTP::uri] contains "/xyz_QuotationService" } { node 172.27.117.68 99 }

     

    else { pool pool_default }

     

    }

     

  • Try below iRule. Hope it will fit in your box.

      when HTTP_REQUEST 
        { if { [HTTP::uri] contains "/abc/efg/Contract" } { HTTP::redirect "http://172.27.117.69:89/acldata.asmx"}
        elseif { [HTTP::uri] contains "/xyz_QuotationService" } { HTTP::redirect "http://172.27.117.69:89/ACLData.asmx" }
        else { pool pool_default }
            } 
    
    • AshuA_246482's avatar
      AshuA_246482
      Icon for Nimbostratus rankNimbostratus

      Hi F5_Rock,

       

      Thanks for your response.

       

      For a external user doesn't http redirect will throw 30X to user request and user will be pointed to internal url in his browser then it will become unavailable for a external user ? because middleware is internal and not exposed to internet.

       

    • AshuA_246482's avatar
      AshuA_246482
      Icon for Nimbostratus rankNimbostratus

      Hi Only1masterblaster,

       

      What kind of further work is expected? can you please give me some idea ?

       

      Thanks

       

  • Think this is what you want to do, match a URI set change the URI before selecting a node to forward on to.

    Technically you do not need the final default pool so I have left it out, will select this by default if the iRule returns without making a pool or node selection.

    when HTTP_REQUEST {
      if {[HTTP::uri] contains "/abc/efg/Contract" } {  
        HTTP::uri "/acldata.asmx"    
        node 172.27.117.68 89 
      } elseif {[HTTP::uri] contains "/xyz_QuotationService"} {      
        HTTP::uri “/ACLData.asmx"    
        node 172.27.117.68 99   
      } 
    }