For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

iRule's avatar
iRule
Icon for Cirrus rankCirrus
Aug 01, 2021

Redirect requests of all URLs except few URLs

Dear Beloved Community,

I have a requirement to fulfill in LTM as below for which I need your support to provide me an iRule.

 

Client requests containing any URIs should be redirected as below

https://abc.com redirect to https://xyz.com

 

But If client requests contains any of following URIs then do not perform redirection to https://xyz.com

https://abc.com/morning

OR

https://abc.com/afternoon

OR

https://abc.com/night

OR

https://abc.com/school

OR

https://abc.com/leadership

 

Your Sincerely

6 Replies

  • Hi,

    when HTTP_REQUEST {
    	if { [HTTP::host] equals "abc.com" } {
    		switch [string tolower [HTTP::uri]] {
    			"/morning" -
    			"/afternoon" -
    			"/night" -
    			"/school" -
    			"/leadership" { }
    			default {
    				HTTP::redirect https://xyz.com[HTTP::uri]
    				return
    			}
    		}
    	}
    }
  • Hi Enes,

    Thank you for your input.

     

    I have tested this iRule but all the URLs including "/morning" , "/afternoon" , "/night" , "/school" , "/leadership" are being redirected while the requirement is few URLs should not redirect and the remaining all other should redirect.

  • Do the urls start with "/morning", "/afternoon", "/night", "/school", "/leadership" or are they exactly equals?

    when HTTP_REQUEST {
    	if { [HTTP::host] equals "abc.com" } {
    		switch -glob [string tolower [HTTP::uri]] {
    			"/morning*" -
    			"/afternoon*" -
    			"/night*" -
    			"/school*" -
    			"/leadership*" {
    				log local0. "not redirect - uri: [HTTP::uri]"
    			}
    			default {
    				log local0. "redirect - uri: [HTTP::uri]"
    				HTTP::redirect https://xyz.com[HTTP::uri]
    				return
    			}
    		}
    	}
    }

    Can you investigate the ltm logs?

    • iRule's avatar
      iRule
      Icon for Cirrus rankCirrus

      The URLs are exactly same. So I am still using the first iRule, which you provided. Any idea how we can fix it. I am searching LTM logs in GUI by filtering logs with VS name but no logs are appearing.

      • when HTTP_REQUEST {
        	log local0. "vs: [virtual name] uri: [HTTP::uri] host: [HTTP::host]"
        	
        	if { [HTTP::host] equals "abc.com" } {
        		switch [string tolower [HTTP::uri]] {
        			"/morning" -
        			"/afternoon" -
        			"/night" -
        			"/school" -
        			"/leadership" {
        				log local0. "not redirect - vs: [virtual name] uri: [HTTP::uri]"
        			}
        			default {
        				log local0. "redirect - vs: [virtual name] uri: [HTTP::uri]"
        				HTTP::redirect https://xyz.com[HTTP::uri]
        				return
        			}
        		}
        	}
        }

        You can use the following command to filtering.

        tail -f /var/log/ltm | grep irulename