Forum Discussion
Brent_Sachnoff_
Nimbostratus
May 24, 2006funny things happen with basic iRule
Hi. I have this iRule that appeared to work the first couple of times around and now only works for the 1,2 and last case within the if clause. I'm sure there is a better way to write it but I'm still learning:
when HTTP_REQUEST {
if { [HTTP::host] starts_with "a.company.com" }
{ HTTP::redirect "https://www.company.com/123/Login.html" }
elseif { [HTTP::host] starts_with "company.com" }
{ HTTP::redirect "https://www.company.com/123/Login.html" }
elseif { [HTTP::uri] equals "/" }
{ HTTP::redirect "https://[HTTP::host]/123/Login.html" }
elseif { [HTTP::uri] equals "/Login.html" }
{ HTTP::redirect "https://[HTTP::host]/123/Login.html" }
elseif { [HTTP::uri] equals "/456/index.html" }
{ HTTP::redirect "https://[HTTP::host]/123/Login.html" }
elseif { [HTTP::uri] equals "/mobileLogin.html" }
{ HTTP::redirect "https://[HTTP::host]/123/Login.html" }
else { HTTP::redirect https://[HTTP::host][HTTP::uri] }
}
Any reason for this not to work for all the clauses above?
Thanks!
- As long as the rule can compile (due to the elseif's on new lines), then it should functionaly work. I would add some logging in to output the values of the HTTP::host and HTTP::uri variables and then a log statement for the condition that matched. starts_with and equals are case-sensitive. Maybe that could be the issue. No way to tell without some input data.
when HTTP_REQUEST { log local0. "Host: [HTTP::host], URI: [HTTP::uri]" if { [HTTP::host] starts_with "a.company.com" } { log local0. "host matched a.company.com" HTTP::redirect "https://www.company.com/123/Login.html" } elseif { [HTTP::host] starts_with "company.com" } { log local0. "host matched company.com" HTTP::redirect "https://www.company.com/123/Login.html" } elseif { [HTTP::uri] equals "/" } { log local0. "URI matched '/'" HTTP::redirect "https://[HTTP::host]/123/Login.html" } elseif { [HTTP::uri] equals "/Login.html" } { log local0. "URI matched /Login.html" HTTP::redirect "https://[HTTP::host]/123/Login.html" } elseif { [HTTP::uri] equals "/456/index.html" } { log local0. "URI matched /456/index.html" HTTP::redirect "https://[HTTP::host]/123/Login.html" } elseif { [HTTP::uri] equals "/mobileLogin.html" } { log local0. "URI matched /mobileLogin.html" HTTP::redirect "https://[HTTP::host]/123/Login.html" } else { log local0. "URI match not found, using default case" HTTP::redirect https://[HTTP::host][HTTP::uri] } }
- Brent_Sachnoff_
Nimbostratus
Joe, - So are you saying that for some URI's you are getting the first logging line and for some URI's you are not? That doesn't make any sense. You should be hitting the HTTP_REQUEST event for each HTTP request and the first log command should always execute.
set newUri [string tolower [HTTP::uri]] if { $newUri starts_with ... } { ... }
- Brent_Sachnoff_
Nimbostratus
That is exactly what I am saying. Sometimes when I hit the url it logs and when I try to hit the 2 cases it never logs anything. Regardless, it should always log something for me. Very weird. - hoolio
Cirrostratus
You might want to give the box a kick by running bigstart restart when you are able to (this will restart the processes on the BIG-IP and drop all existing connections).
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