Forum Discussion

Domai_23823's avatar
Domai_23823
Icon for Nimbostratus rankNimbostratus
Aug 22, 2018

iRule URI replace help

Hello All - I need help to fix the below iRule

Requirement is when the user types in https://apple.api.com/e/apple/console/ the uri /e/apple/ should be replaced by /console so its going to be https://apple.api.com/console/ The below iRule accomplishes that but when user types in https://apple.api.com/e/apple/console without the '/' after console it does nothing. It only works when user types '/' at the end.

when HTTP_REQUEST {
    log local0. "Incoming URI = [HTTP::uri]"
    if { [string tolower [HTTP::uri]] starts_with "/e/apple/" } {
        set uri [string map -nocase {"/e/apple/" "/"} [HTTP::uri]]
        log local0. "New URI = $uri"
        HTTP::uri $uri
        virtual apple.api_vs_4001
        log local0. "Host header is [HTTP::host]"
    }
}
  • Can we assume the log statement is returning the correct value?

     

    When you say "it does nothing", can you elaborate?

     

    Can the server actually handle the URL without the trailing "/"?

     

  • Hi Domai,

    I understand your problem. If you not put / after console at the end of th uri, it's not working. I advise you to rewrite your uri in order to add "/" at the end of uri if it's not present.

    Please try this Irule, it will fix your problem

    when HTTP_REQUEST {
        log local0. "Incoming URI = [HTTP::uri]"
        if { [string tolower [HTTP::uri]] starts_with "/e/apple/" } {
    
    
            if { [string tolower [HTTP::uri]] contains "/console/" } {
                set uri [string map [ list "/e/apple/" "/" "/console" "/console/" ] [HTTP::uri]]
            } else {
                set uri [string map -nocase {"/e/apple/" "/"} [HTTP::uri]]
            }
    
            log local0. "New URI = $uri"
            HTTP::uri $uri
            virtual apple.api_vs_4001
            log local0. "Host header is [HTTP::host]"
        }
    }
    

    Keep me in touch if it working for your.

    Regards

  • Hello Kevin when I say nothing I meant that page does not load it just hangs.

     

  • I don't see anything particularly wrong with the iRule logic, so I have to wonder if the server actually understands the "/console" URI (vs. "/console/").

     

  • And the log statement is returning the correct value only when user types in /in the end or else it does not return the correct value. For example when user types /p/apple/console/ it shows incoming uri as /p/apple/console/ and new uri as /console/

     

    But when user types in /p/apple/console, it shows incoming uri as /console/ and that that is it.

     

  • This may require deeper inspection of the HTTP traffic flow, as there maybe client side processing affecting the interaction. Can you display the results of a simple Fiddler capture (with both URLs)?

     

  • I have the screenshot...can I get your email so that I can mail it to you directly. I am unable to upload it here using insert image option.