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

SteveEason's avatar
Dec 11, 2020
Solved

iRule to reroute to new site while evaluating variables

We have to route a website to a new website while maintaining the variables in the URL, and then append a new variable. I have that iRule working. However, there is a complication. There are 3 variab...
  • Enes_Afsin_Al's avatar
    Dec 11, 2020

    Hi SteveEason,

    string tolower: Returns lowercase value.

    when HTTP_REQUEST {
    	if { [string tolower [HTTP::host]] contains "code1"} {
    		HTTP::redirect "https://www.newwebsite.com/Code1&fcRedirect=true"
    	}
    	elseif { [string tolower [HTTP::host]] starts_with "code2"} {
    		HTTP::redirect "https://www.newwebsite.com/Code2&fcRedirect=true"
    	}  
    	elseif { [string tolower [HTTP::host]] starts_with "code3"} {
    		HTTP::redirect "https://www.newwebsite.com/Code3&fcRedirect=true"
    	}
    	else {
    		HTTP::redirect "https://www.newwebsite.com[HTTP::uri]&fcRedirect=true"
    	}
    }

    switch version:

    when HTTP_REQUEST {
    	switch -glob [string tolower [HTTP::host]] {
    		"*code1*" { HTTP::redirect "https://www.newwebsite.com/Code1&fcRedirect=true" }
    		"*code2*" { HTTP::redirect "https://www.newwebsite.com/Code2&fcRedirect=true" }
    		"*code3*" { HTTP::redirect "https://www.newwebsite.com/Code3&fcRedirect=true" }
    		default { HTTP::redirect "https://www.newwebsite.com[HTTP::uri]&fcRedirect=true" }
    	}
    }

    If codeX tags are contained in uri instead of host, you should use [HTTP::uri] instead of [HTTP::host].

    when HTTP_REQUEST {
    	switch -glob [string tolower [HTTP::uri]] {
    		"*code1*" { HTTP::redirect "https://www.newwebsite.com/Code1&fcRedirect=true" }
    		"*code2*" { HTTP::redirect "https://www.newwebsite.com/Code2&fcRedirect=true" }
    		"*code3*" { HTTP::redirect "https://www.newwebsite.com/Code3&fcRedirect=true" }
    		default { HTTP::redirect "https://www.newwebsite.com[HTTP::uri]&fcRedirect=true" }
    	}
    }