Technical Forum
Ask questions. Discover Answers.
cancel
Showing results for 
Search instead for 
Did you mean: 

iRule creation based on URI

MikeyG
Nimbostratus
Nimbostratus

disclaimer, I do not know iRules for anything......but I have been asked to create on for the following.

here are my requirements, iRule to redirect traffic .

1. if this = https://abc.help.com/support/case/v2/WebCase  respond to here = sa.abcs.help.com

 

2. if this = https://abc.help.com/HBServices/abc/v1/asset/$uri respond to here - hb.abcs.help.com

3. if this = https://abc.help.com/support/assetinfo/v4/getassetwarranty/$uri respondwith 404

 

4. if this = https://abc.help.com/$uri  respond to here = abc2.us.help.com

 

Here is what I tried .

when HTTP_REQUEST {

if {

([string tolower [HTTP::host]] equals "abc.help.com") &&

([HTTP::uri] contains "/support/case/v2/WebCase")

}

{

HTTP::redirect "https://sa.abcs.help.com[HTTP::uri]"

}

}

 

elseif {

([string tolower [HTTP::host]] equals "abc.help.com") &&

([HTTP::uri] contains "/hbserial/abc/v1/asset/$uri")

}

{

HTTP::redirect "https://hb.abcs.help.com[HTTP::uri]"

}

}

 

elseif {

([string tolower [HTTP::host]] equals "abc.help.com") &&

([HTTP::uri] contains "/support/assetinfo/v4/getassetwarranty/$uri")

}

{

HTTP::respond "404 [HTTP::uri]"

}

}

 

elseif {

([string tolower [HTTP::host]] equals "abc.help.com") &&

([HTTP::uri] contains "/$uri")

}

{

HTTP::redirect "https://abc2.us.help.com[HTTP::uri]"

}

}

 

 

2 REPLIES 2

Hi MikeyG,

when HTTP_REQUEST {
	if { [HTTP::host] equals "abc.help.com" } {
		switch -glob [string tolower [HTTP::uri]] {
			"/support/case/v2/webcase*" { HTTP::redirect https://sa.abcs.help.com[HTTP::uri] }
			"/hbservices/abc/v1/asset*" { HTTP::redirect https://hb.abcs.help.com[HTTP::uri] }
			"/support/assetinfo/v4/getassetwarranty*" { HTTP::respond 404 content "404 Page Not Found" }
			default { HTTP::redirect https://abc2.us.help.com[HTTP::uri] }
		}
	}
}

Thank you, i am getting better but I just do not do them very often.