Forum Discussion
Jeremy_C_Russel
Nimbostratus
Nov 14, 2011Possible issue with an iRule
Greetings all.
I wanted to get some eyes on this particular rule I've setup. The premise is to take urls in the form of http://string.domain.com or http://www.string.domain.com, capture "string" and redirect to a new url, http://www.domain.com/SomeURI?a= where we append the captured string.
I've tested this and it works fine, but for some folks its errors.. in IE, is give them a 404 and in Firefox, it's complaining of a "Connection Reset".
I can't see anything as to why this would be caused.
if { [regexp {www} [HTTP::host]] } {
scan [HTTP::host] {%[^.].%[^.].%s} www host dom
} else {
scan [HTTP::host] {%[^.].%s} host dom
}
if { not [regexp {domain|www|wsecure|ssl} $host] } {
log local0. "Caught a MS host $host, redirecting..."
HTTP::redirect "https://www.domain.com/MS/RedirectMS?site=hub&value=$host"
}
- nitass
Employee
not sure if adding log command is helpful in troubleshooting.[root@ve1023:Active] config b rule myrule list rule myrule { when HTTP_REQUEST { set www "" if {[regexp {www} [HTTP::host]]} { scan [HTTP::host] {%[^.].%[^.].%s} www host dom } else { scan [HTTP::host] {%[^.].%s} host dom } log local0. "[IP::client_addr]:[TCP::client_port]|[HTTP::host]|[HTTP::uri]|$www|$host|$dom" if {not [regexp {domain|www|wsecure|ssl} $host]} { log local0. "Caught a MS host $host, redirecting..." HTTP::redirect "https://www.domain.com/MS/RedirectMS?site=hub&value=$host" } } } [root@ve1023:Active] config curl -I http://abc.com/test HTTP/1.0 302 Found Location: https://www.domain.com/MS/RedirectMS?site=hub&value=abc Server: BigIP Connection: Keep-Alive Content-Length: 0 [root@ve1023:Active] config Nov 14 00:40:24 local/tmm info tmm[4766]: Rule myrule : 172.28.65.150:53712|abc.com|/test||abc|com Nov 14 00:40:24 local/tmm info tmm[4766]: Rule myrule : Caught a MS host abc, redirecting... [root@ve1023:Active] config curl -I http://www.abc.com/test HTTP/1.0 302 Found Location: https://www.domain.com/MS/RedirectMS?site=hub&value=abc Server: BigIP Connection: Keep-Alive Content-Length: 0 [root@ve1023:Active] config Nov 14 00:40:31 local/tmm info tmm[4766]: Rule myrule : 172.28.65.150:53713|www.abc.com|/test|www|abc|com Nov 14 00:40:31 local/tmm info tmm[4766]: Rule myrule : Caught a MS host abc, redirecting...
- hoolio
Cirrostratus
If you're seeing connection resets with an iRule, check the /var/log/ltm file for runtime TCL errors.when HTTP_REQUEST { Remove www. from the host header value if it is present set host [string map {www. ""} [string tolower [HTTP::host]]] log local0. "[IP::client_addr]:[TCP::client_port]: Parsed $host from [HTTP::host]" switch $host { "domain" - "wsecure" - "ssl" { log local0. "[IP::client_addr]:[TCP::client_port]: Matched part of $host, redirecting" HTTP::redirect "https://www.domain.com/MS/RedirectMS?site=hub&value=$host" } } }
- nitass
Employee
Aaron,[root@ve1023:Active] config b rule myrule list rule myrule { when HTTP_REQUEST { Remove www. from the host header value if it is present scan [string map {www. ""} [string tolower [HTTP::host]]] {%[^.]} host log local0. "[IP::client_addr]:[TCP::client_port]: Parsed $host from [HTTP::host]" switch $host { "domain" - "wsecure" - "ssl" { do something } default { log local0. "[IP::client_addr]:[TCP::client_port]: Matched part of $host, redirecting" HTTP::redirect "https://www.domain.com/MS/RedirectMS?site=hub&value=$host" } } } } [root@ve1023:Active] config curl -I http://www.abc.com/test HTTP/1.0 302 Found Location: https://www.domain.com/MS/RedirectMS?site=hub&value=abc Server: BigIP Connection: Keep-Alive Content-Length: 0 [root@ve1023:Active] config Nov 14 07:29:34 local/tmm info tmm[4766]: Rule myrule : 172.28.65.150:46973: Parsed abc from www.abc.com Nov 14 07:29:34 local/tmm info tmm[4766]: Rule myrule : 172.28.65.150:46973: Matched part of abc, redirecting [root@ve1023:Active] config curl -I http://abc.com/test HTTP/1.0 302 Found Location: https://www.domain.com/MS/RedirectMS?site=hub&value=abc Server: BigIP Connection: Keep-Alive Content-Length: 0 [root@ve1023:Active] config Nov 14 07:29:43 local/tmm info tmm[4766]: Rule myrule : 172.28.65.150:46974: Parsed abc from abc.com Nov 14 07:29:43 local/tmm info tmm[4766]: Rule myrule : 172.28.65.150:46974: Matched part of abc, redirecting
- hoolio
Cirrostratus
Good catch Nitass. I was going to use getfield to parse it, but forgot about it. scan should be able the same efficiency. - Jeremy_C_Russel
Nimbostratus
Thanks for the replies. I do think an error in other parts of the rule was the issue. I have taken your advice though to reduce my use of regexp. Is there a point at which the number of elements in a switch statement starts to be of concern? - Michael_Yates
Nimbostratus
Hi Jeremy,
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