Persistence based on URI regexp

Hello everyone,

I would like to create a persistence rule based on a work order ID in the URI. I have to persist when the URI of my web site contains workorder/WO-123456789 (123456789 = 9 digits). The persistence variable must be the field “WO-123456789”.

This is the iRule I’ve created but my regexp is not working as expected:

when HTTP_REQUEST { set uri [HTTP::uri] if { $uri matches_regex “workorder/WO-\d\d\d\d\d\d\d\d\d” } { set woid [findstr $uri “workorder” 10 “/”] persist uie $woid log local0. “persist OK workorder id found. URI = $uri / workorderID = $woid” } else { log local0. “URI workorderID not found. URI = $uri” } }

The logs received show me that I’m always going to the “else” part of my iRule, but I can see that the real URI contains what is expected.

Can you tell me what is wrong in my code?

Best regards, Fabien

Hi,

you can try this code:

when HTTP_REQUEST {
    set uri [HTTP::uri]
    if { $uri contains "workorder/WO-" && [regexp {workorder/(WO-\d\d\d\d\d\d\d\d\d).*$} $uri garbage woid]} {
        persist uie $woid
        log local0. "persist OK workorder id found. URI = $uri / workorderID = $woid"
    } else {
        log local0. "URI workorderID not found. URI = $uri"
    }
}