Forum Discussion
Phil_Lawrence_7
Nimbostratus
Nov 11, 2011Irule to redirect based on host and uri - lowercase issue
Hi
We are using BigIP v9.x
Im new to irules and I have done some searching on this forum and from the examples I've found ive managed to write the following (which works)
when HTTP_REQUEST { if {[HTTP::host] == "wibble.com" and [HTTP::uri] contains "&lang=Anon&country=Anon"}{
if {[scan [HTTP::uri] "/livelink/livelink.exe?func=ll&objid=%d&objAction=%s" dnum action] == 2} {
HTTP::redirect "http://wibble.com/otcs/livelink.exe?func=LL.login&username=Myuserid&password=XYZ&NextURL=%2Fotcs%2Flivelink%2Eexe%3Ffunc%3Dll%26objId%3D$dnum%26objAction%3D$action"
}
}
}
the logic behind this is .....
original url
http://wibble.com/livelink/livelink...untry=Anon
redirect all trafffic from http://wibble.com that has "&lang=Anon&country=Anon" in the url
Put the numeric value after objid= into a variable dnum and the word after objaction and before the & into a variable called action
this works, however the action variable contains the rest of the URI, which whilst not ideal is working for us.
I have found an error where if someone puts the url in a different case, it fails ... so I've been trying to use the tolower command, but I get an error saying that tolower is not a valid maths function
when HTTP_REQUEST {
if {tolower([HTTP::host]) == "wibble.com" and tolower([HTTP::uri]) contains "&lang=anon&country=anon"}{
if {[scan [HTTP::uri] "/livelink/livelink.exe?func=ll&objid=%d&objAction=%s" dnum action] == 2} {
HTTP::redirect "http://wibble.com/otcs/livelink.exe?func=LL.login&username=Myusername&password=XYZ&NextURL=%2Fotcs%2Flivelink%2Eexe%3Ffunc%3Dll%26objId%3D$dnum%26objAction%3D$action" } } }
once this is working I can then do the next section which is dependant on if the objaction in the url = open, do one redirect, else do another ... however this now seems very long and a little unweildy
when HTTP_REQUEST {
if {tolower([HTTP::host]) == "ecm.express.tnt" and tolower([HTTP::uri]) contains "&lang=anon&country=anon"}{
if {tolower([HTTP::uri]) contains "objaction=open"}{
if {[scan [HTTP::uri] "/livelink/livelink.exe?func=ll&objid=%d&objAction=%s" dnum action] == 2} {
HTTP::redirect "http://ecm.express.tnt/otcs/livelink.exe?func=LL.login&username=Anonymous&password=&NextURL=%2Fotcs%2Flivelink%2Eexe%3Ffunc%3Ddoc%2Efetch%26nodeid%3D$dnum"
}
} else if {[scan [HTTP::uri] "/livelink/livelink.exe?func=ll&objid=%d&objAction=%s" dnum action] == 2} {
HTTP::redirect "http://ecm.express.tnt/otcs/livelink.exe?func=LL.login&username=Anonymous&password=&NextURL=%2Fotcs%2Flivelink%2Eexe%3Ffunc%3Dll%26objId%3D$dnum%26objAction%3D$action"
}
}
}
any advice would be welcomed
Thanks in Advance
Phil
- nitass
Employee
not sure if i read your rule correctly or not. please feel free to revise.[root@ve1023:Active] config b virtual bar list virtual bar { snat automap pool foo destination 172.28.65.152:http ip protocol tcp rules myrule profiles { http {} tcp {} } } [root@ve1023:Active] config b rule myrule list rule myrule { when HTTP_REQUEST { set http_uri [string tolower [HTTP::uri]] if {[string tolower [HTTP::host]] equals "ecm.express.tnt"} { if {$http_uri ends_with "&lang=anon&country=anon"} { set dnum [URI::query $http_uri "objid"] set action [URI::query $http_uri "objaction"] if {$action equals "open" and $dnum ne ""} { HTTP::redirect "http://ecm.express.tnt/otcs/livelink.exe?func=LL.login&username=Anonymous&password=&NextURL=%2Fotcs%2Flivelink%2Eexe%3Ffunc%3Ddoc%2Efetch%26nodeid%3D$dnum" } else { do something else } } } } } [root@ve1023:Active] config curl -I "http://ecm.express.tnt/livelink/livelink.exe?func=ll&objid=149998544&objAction=open&lang=Anon&country=Anon" HTTP/1.0 302 Found Location: http://ecm.express.tnt/otcs/livelink.exe?func=LL.login&username=Anonymous&password=&NextURL=%2Fotcs%2Flivelink%2Eexe%3Ffunc%3Ddoc%2Efetch%26nodeid%3D149998544 Server: BigIP Connection: Keep-Alive Content-Length: 0
- Hi,
- Phil_Lawrence_7
Nimbostratus
thank you both for taking the time to help - nitass
Employee
im assuming the ne in ($dnum ne "") is "not equal to" yes, it is. - Phil_Lawrence_7
Nimbostratus
Hi
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects