Forum Discussion

eran's avatar
eran
Icon for Nimbostratus rankNimbostratus
Jan 03, 2023

irule redirect with partial URI

hi i need some assitance to my current irule that i created to catch a uri and then delete the the folder path and resend the request to another virtual server i have. i have tried to redirect to the new virtual server pool also.

and im haveing abit of issues to catch upper and also lower case letters, meaing i want to catch the word abc and also Abc witch ever the word the user type. and then redirect the same host and the parameter of the uri to the new pool.

heres an example

original request ====>   https://hostname.com/Abc/?doc=9999&cont=1000 

needed request ====>  https://hostname.com/?doc=9999&cont=1000 

my irule

when HTTP_REQUEST {
    if {string tolower [HTTP::uri] starts_with  "/Abc" } {
        HTTP::uri [string  map {"/abc" ""}[HTTP::uri]]
        pool <new pool>
    }
}

2 Replies

  • you're close, but you're missing some brackets around your string tolower as well as the fact that it will never match if you've lowered the letters but are trying to match against an upper in your match string. 

    when HTTP_REQUEST {
        if { [string tolower [HTTP::uri]] starts_with "/abc" } {
            HTTP::uri [string map {"/abc" ""} [HTTP::uri]]
            pool <new pool>
        }
    }
    
    ### alternative
    when HTTP_REQUEST {
        if { [string tolower [HTTP::uri]] starts_with "/abc" } {
            HTTP::uri [string range [HTTP::uri] 4 end]
            pool <new pool>
        }
    }

    I propose the alternative because it is ever-so-slightly faster per iteration:

    % set uri /abc/?doc=9999&cont=1000
    /abc/?doc=9999&cont=1000
    % time { string range $uri 4 end} 100000
    0.6844128599999999 microseconds per iteration
    % time { string map {"/abc" ""} $uri} 100000
    0.7239472299999999 microseconds per iteration

     

  • When you use string to lower, you need to use lower case in the string you want to match. So try starts_with "abc" not "Abc"