Forum Discussion

Samuel_Neff_133's avatar
Samuel_Neff_133
Icon for Nimbostratus rankNimbostratus
Dec 22, 2014

Need Direction - URI Rewrite + Pool Selection

I have been asked to see if the F5 can accomplish a few things. And I need some direction. 1. We have an in-house application that runs on a pair of webservers, we want users to have one url to use and be sorted between the webservers base upon uri. I have done something similar with an iRule before and it would look like this:

    when HTTP_REQUEST {
     Check URI set to lower case with wildcard matching
     log local0. "Requested hostname: [HTTP::host] from IP: [IP::local_addr] and URI: [HTTP::uri]"
    
     
    switch -glob [string tolower [HTTP::uri]] {
        "/raloh*" {
            pool pool_WES-PROD-http-8080
        }
        default {
            pool pool_WES-PROD-http-8081
        }
    }
}
  1. We want to remove the first section of the URI and replace with /UI/Portal/ as the the webserver on the other side cannot make since of the part of the URI(/raloh) that they want to use to switch between servers. So One user goes to test.WESserver.com/raloh/UI/Portal - should go to the 8080 pool as /UI/Portal. The second user goes to test.WESserver.com/mumrah/UI/Portal - should go to the 8081 pool as /UI/Portal

So I was thinking content rewrite could be used to do this, as the external DNS name is different from the internalm port is different IP and DNS are the same internally, but how to switch and strip the first section?

4 Replies

  • you can do that with a simple string map, shown here in the tcl shell on the BIG-IP:

    % set x "/raloh/realurl"
    /raloh/realurl
    % string map { /raloh "" } $x
    /realurl
    
  • This could accomplish your goal:

    when HTTP_REQUEST {
         Check URI set to lower case with wildcard matching
         log local0. "Requested hostname: [HTTP::host] from IP: [IP::local_addr] and URI: [HTTP::uri]"
        
         
        switch -glob [string tolower [HTTP::uri]] {
            "/raloh*" {
                HTTP::uri "/UI/Portal"
                pool pool_WES-PROD-http-8080
            }
            "/mumrah*" {
                HTTP::uri "/UI/Portal"
                pool pool_WES-PROD-http-8081
            }
            default {
                pool pool_WES-PROD-http-8081
            }
        }
    }
    
  • if you want to strip all the contents before the 2nd slash, this alternative solution will work:

    % set x "/raloh/realurl"
    /raloh/realurl
    % string range $x [string first "/" $x 1] end
    /realurl