Forum Discussion

WaterlooSysAdmi's avatar
Aug 28, 2019

IRule - Routing

Hello,

 

I need to apply two iRules to a virtual server. One that routes traffic to a certain pool of servers based on the release version in url, 8.32.4. Say https://test.abc.com/dr=dfgv8.32.4 the version stay the same in the string but the letters around will change. Maybe a contains?

 

A second that routes based on cookie. If we don’t find this release version in the url the second irule will kick in and search for cookie if it finds the cookie it will route to a certain pool of servers.

 

if none of the irules kick in traffic just goes to the pool of servers attached to the VS.

 

does anyone know how these might look?

 

thank you for the help

 

6 Replies

  • Hi,

    when HTTP_REQUEST {
        if { [HTTP::uri] contains "8.32.4" } {
            pool pool_A
        } elseif { [HTTP::cookie exists "cookieName"] } {
            pool pool_B
        }
    }

    If the version number is at end of the uri, you can use "ends_with" operator.

    when HTTP_REQUEST {
        if { [HTTP::uri] ends_with "8.32.4" } {
            pool pool_A
        } elseif { [HTTP::cookie exists "cookieName"] } {
            pool pool_B
        }
    }
  • Great, thank you for the help! I'll plan on testing over the next couple of days and let you know.

     

  • ok, so i ran into an issue with the cookie. The cookie for example will always be "cookieName" but I need to route according to the version that's inside the cookie. Is there an irule that will do that?

    • Enes_Afsin_Al's avatar
      Enes_Afsin_Al
      Icon for MVP rankMVP

      Hi,

      Can you try this iRule?

      when HTTP_REQUEST {
      	if { [HTTP::cookie exists "cookieName"] } {
      		set cookieValue [HTTP::cookie value "cookieName"]
      		# log local0. "CookieValue: $cookieValue"
      		
      		if { $cookieValue contains "8.32.4" } { pool pool_A }
      		elseif { $cookieValue contains "8.32.5" } { pool pool_B }
      		else { pool pool_Z }
      	}
      	else {
      		pool pool_default
      	}
      }
  • hello,

     

    this is working!, thank you. Is it possible to add routing bases on Referer as well?