Forum Discussion

Steve_Sutton_87's avatar
Steve_Sutton_87
Icon for Nimbostratus rankNimbostratus
May 04, 2005

why is log statement in else clause executing?

Hi,

 

 

I have the following rule:

 

 

if (http_uri == "/") {

 

log local0.info "test09si: redirected incomplete URI"

 

redirect to "https://%h/Test01_09"

 

}

 

else if (http_uri starts_with "/Test01_09") {

 

use pool test01-8180

 

}

 

else {

 

log local0.info "test09si: redirected for bad path "

 

redirect to "https://alpha.blueroads.com/error/404.html"

 

}

 

 

If I browse to https://test09si.blueroads.com, the if clause correctly redirects with the path, and the else if apparently evaluates true because I get to the web site just fine. However, the "log local0.info "test09si: redirected for bad path " is also being executed - in a fraction of a second I get both log messages logged into /var/log/bigip. But even though we appear to be stepping into the else clause, I don't get redirected to the 404 error page (that's a good thing, at least).

 

 

If I indeed provide a bad path, such as https://test09si.blueroads.com/Test01_08, the else if is indeed false, and we drop into the else, and both the log and redirect in the else clause execute.

 

 

Why is the log statement in the else clause executing?

 

 

Cheers,

 

Steve

 

4 Replies

  • Could it be that the contents of your website's html code references another uri on that is causing the else clause to catch? First thing I'd do is to log the http_uri value at the beginning of the rule and then look at the logs. I'd be surprised if you see the "if" log statement followed by the "else". Odds are that another uri is slipping in under the covers somewhere (that would explain why the main page is redirecting correctly). Take a look and let us know.

     

     

    -Joe
  • I'd log the http_uri value if I could - but the log command doesn't appear to expand the http_uri variable? The doc says the log command will do variable expansion as in the header insert pool attribute. Looking at that, there are variables for client address and port, server address and port, link_qos and ip_qos - nothing that would provide either the path, or host, or even the entire URL.

     

     

    And indeed there is redirection occurring once one hits the Tomcat server - the final URL is https://test09si.blueroads.com/Test01_09/Login.do - the "/Test09" tells Tomcat/Jboss which context to use, and code in the app server does the rest of the work.

     

     

    I added a log statement to the else if clause, and sent my browser to https://test09si.blueroads.com, which eventually landed me on the above page. Here's what was in the log:

     

     

    May 5 10:00:37 cerebus kernel: RULE test09si-URICheck-Pool_test01 - test09si: redirected incomplete URI http_uri

     

    May 5 10:00:37 cerebus kernel: RULE test09si-URICheck-Pool_test01 - test09si: found URI path http_uri

     

    May 5 10:00:37 cerebus last message repeated 13 times

     

    May 5 10:00:42 cerebus kernel: RULE test09si-URICheck-Pool_test01 - test09si: redirected for bad path http_uri

     

     

    Note that "http_uri" is treated simply as a string in the log command. There are a number of images on the page, which presumably accounts for the 14 times through the else if clause. But in looking at the source for the page, there are no references to any images, etc. that are outside of test09si.blueroads.com/Test01_09. There are a couple of href's that are links to other sites, but they won't activate unless one clicks on the links.

     

     

    So, I'm at a loss here. Guess I may have to crank up tcpdump to see what my browser is sending through.

     

  • Martin_Machacek's avatar
    Martin_Machacek
    Historic F5 Account
    Use:

    
    if (http_uri == "/") {
       log local0.info "test09si: redirected incomplete URI"
       redirect to "https://%h/Test01_09"
    } else if (http_uri starts_with "/Test01_09") {
       use pool test01-8180
    }
    else {
       log local0.info "test09si: redirected for bad path: " + http_uri
       redirect to "https://alpha.blueroads.com/error/404.html"
    }  

    to include the URI in the log message.