Forum Discussion

tran_93981's avatar
tran_93981
Icon for Nimbostratus rankNimbostratus
Oct 30, 2015

direct request traffic to the specific directory of another server

I am struggling to write an iRule to achieve this objective:

My iRules is this

when HTTP_REQUEST {
 log local0. "URL:'[HTTP::host][HTTP::uri]'"
    if {([HTTP::uri] starts_with "/engineering/las")} {
     HTTP::uri "/las"
        node 10.10.10.1:9290
        log local0. "lAS URL:'[HTTP::host][HTTP::uri]' from [IP::local_addr]"
   }
   elseif {([HTTP::uri] starts_with "/engineering/thredds")} {
     HTTP::uri "/thredds"
        node 10.10.10.1:9290
        log local0. "THREDDS URL:'[HTTP::host][HTTP::uri]' from [IP::local_addr]"
   }
       elseif {([HTTP::uri] starts_with "/coads/las")} {
       HTTP::uri "/las"
        node 10.10.10.1:9280
        log local0. "COADS URL:'[HTTP::host][HTTP::uri]' from [IP::local_addr]"
 }
}

The problem I am experiencing with this iRule is the pages are not fully displayed (the pages have some script running and it is located on 10.10.10.1:9290/las) and when user click "refresh" then the page will be displayed "not found". I think when it happens like that the uri on the client side is no longer /engineering/thredds, /engineering/las, or /coads/las but it is /las or /thredds so the requests is http://publicpage.com/las not http://publicpage.com/engineering/las which then go to the default pool by the iRule.

Any suggestions, ideas on how to achieve the objective or fix the problem?

Thanks a lot

  • Lucas_Thompson_'s avatar
    Lucas_Thompson_
    Historic F5 Account

    Probably at least part of what's happening is that the client will request something like:

     

    /coads/las/image.png

     

    but then your irule rewrites the request URI part into:

     

    /las

     

    The server will then respond with the default page for "https://whatever.com/las/", causing all kinds of havoc because the browser will think it's requesting JS or CSS or an image or something, but then the server will return the default HTML page.

     

    It's best not to rewrite URIs if you can avoid it because it causes a disconnect in L7 between what the client is requesting and what the server sends back, making troubleshooting very difficult for a web developer. But for your example, you'll need to rewrite ONLY the part you need to rewrite. You can use "string map" or regex, but regex is usually much more expensive. This DevCentral post has a simple example:

     

    https://devcentral.f5.com/questions/search-and-replace-with-irule

     

  • String map won't work for my case because I do not have unique string to map for the IF and Elseif statements. Also the pages that I want to show to users are at specific directory of the servers 10.10.10.1:9290/las, 10.10.10.1:9290/thredds and 10.10.10.1:9280/las.