Forum Discussion

Stefan_Engel's avatar
Nov 17, 2022
Solved

iRule match & processing exit

Hi, 

I'm trying write an iRule for an upcoming migration where we have multiple sites (MS Sharepoint) using the same host with different URI's. Some I want to just forward to a specific pool, while the 'rest' to be redirected to a new page. The 'rest' is basically everything starting with intranet, except some of the specific URI 

 

 

when HTTP_REQUEST 
{ if 
{ ([HTTP::host] starts_with "intranet") && ([HTTP::uri] equals "/AAA/") } { pool intranet_pool 
} elseif
{ ([HTTP::host] starts_with "intranet") && ([HTTP::uri] equals "/BBB/") } { pool intranet_pool 
} elseif
{ [HTTP::host] starts_with "intranet" } { HTTP::redirect https://intranet.new
}}

 

 

I'm facing 2 issues:

  • everything ends up being redirected intranet.new, no matter if the URI is AAA, BBB
  • I'm getting too many redirects with above iRule. If i change the redirect to f5.com it works, but still redirect everything starting with intranet

Do I need to exit the iRule somehow after I got the first match? Or how do I stop further processing? 

I've tried the same with LTM Policy, but getting same results. 

Appreciate your feedback. Thanks.

  • Hi Stefan_Engel,

    In your code, a redirect loop occurs because the redirected page always starts with "intranet". Can you try this iRule?

    when HTTP_REQUEST {
    	if { [HTTP::host] starts_with "intranet" && [HTTP::uri] equals "/AAA/" } {
    		pool intranet_pool
    		return
    	} elseif { [HTTP::host] starts_with "intranet" && [HTTP::uri] equals "/BBB/" } {
    		pool intranet_pool
    		return
    	} elseif { [HTTP::host] starts_with "intranet" && [HTTP::uri] ne "/" } {
    		HTTP::redirect https://intranet.new
    		return
    	}
    }

    If the uri is not "/", it will redirect.
    If the uri is "/", it will not redirect, traffic will be forwarded to the default pool.
    If there is no character after the hostname in url, the uri is always "/".

     

3 Replies

  • Hi Stefan_Engel,

    In your code, a redirect loop occurs because the redirected page always starts with "intranet". Can you try this iRule?

    when HTTP_REQUEST {
    	if { [HTTP::host] starts_with "intranet" && [HTTP::uri] equals "/AAA/" } {
    		pool intranet_pool
    		return
    	} elseif { [HTTP::host] starts_with "intranet" && [HTTP::uri] equals "/BBB/" } {
    		pool intranet_pool
    		return
    	} elseif { [HTTP::host] starts_with "intranet" && [HTTP::uri] ne "/" } {
    		HTTP::redirect https://intranet.new
    		return
    	}
    }

    If the uri is not "/", it will redirect.
    If the uri is "/", it will not redirect, traffic will be forwarded to the default pool.
    If there is no character after the hostname in url, the uri is always "/".

     

  • I would add some log statements to see exactly what you're getting. It could simply be a string case issue.

    On the redirects, your last line is causing this. You're basically saying if the host starts with "intranet", redirect to "intranet.new". But if the same iRule processes intranet.new, then that too will start with "intranet".

    when HTTP_REQUEST { 
      log local0. "Incoming: [HTTP::host][HTTP::uri]"
      if { ( [HTTP::host] starts_with "intranet" ) && ( [HTTP::uri] equals "/AAA/" ) } { 
        log local0. "Catch /AAA/ - Sending to intranet_pool"
        pool intranet_pool 
      } elseif { ( [HTTP::host] starts_with "intranet" ) && ( [HTTP::uri] equals "/BBB/" ) } { 
        log local0. "Catch /BBB/ - Sending to intranet_pool"
        pool intranet_pool 
      } elseif { ( [HTTP::host] starts_with "intranet" ) && ( [HTTP::host] ne "intranet.net" ) } { 
        HTTP::redirect https://intranet.new
      }
    }
  • Thank you both for the response. I've added logging which helped and the ne "/" solved the loop on redirects.