Forum Discussion
JRahm
Oct 20, 2015Admin
I normally prefer a switch over if/else, but in your case, multiple conditions aren't as pretty as to combine you'd end up with nested switch statements. Doable, but ugly. It looks like the flow is:
- Make sure the path is allowed, if not, redirect to
- If the path has already been verified as allowed, check that the referer header contains (X)
- If it doesn't, proceed
- If it does, redirect to http://goodlocation.com
If this is the case, I'd simplify all the logic down to two data-groups and a short iRule:
ltm data-group internal allowed_paths {
records {
/path1/path2/path3 { }
/path1/path2/path5 { }
/path4/path2/path3 { }
/path4/path2/path5 { }
}
type string
}
ltm data-group internal login_required_paths {
records {
anothergoodlocation.com { }
goodlocation.com { }
youcanalsologin.com { }
}
type string
}
when HTTP_REQUEST {
if { [class match [string tolower [HTTP::uri]] starts_with allowed_paths] } {
if { [class match [strint tolower [URI::host [HTTP::header "Referer"]] starts_with login_required_paths] } {
HTTP::redirect "http://goodlocation.com"
}
} else { HTTP::redirect "http://www.notallowed.asp" }
}
This assumes of course you have defined pool POOL_Servers_to_access-80 as the default pool on your virtual server.