Forum Discussion

Sabir_Alvi's avatar
Sabir_Alvi
Icon for Altocumulus rankAltocumulus
May 27, 2021

HTTP::redirect doesn't work for multiple conditions, URL redirect doesn't work using iRule

So I have 2 types of redirects to handle, based on 2 types of URI. When a URI in the HTTP_REQUEST matches the value in Datagroup 1, I want to redirect to a certain URL by retaining a certain part of ...
  • Enes_Afsin_Al's avatar
    May 27, 2021

    Hi Sabir Alvi,

     

    "redirected" variable must be defined before running code for line 8 and line 15.

    If the first if does not match, iRule will give an error, because the "redirected" variable is not defined.

    when HTTP_REQUEST {
    	set redirected "false"
    	set url_hosts [class match -value -- [HTTP::uri] starts_with DATAGROUP_1]
    	if { $url_hosts ne "" } {
    		set redirected "true"
    		set LinkID [URI::query [HTTP::uri] id]
    		HTTP::redirect "https://$url_hosts/links/$LinkID"
    	}
    	if { $redirected ne "true" } {
    		set url_hosts [class match -value -- [HTTP::uri] starts_with DATAGROUP_2]
    		if { $url_hosts ne "" } {
    			set redirected "true"
    			HTTP::redirect "https://$url_hosts"
    		}
    	}
    	if { $redirected ne "true" } {
    		HTTP::respond 404 content "<Some HTML Code for error page>"
    	}
    }