How to match URI string with "#" character?

We have some URI paths where a pound/hash symbol is used; for example:

http::/mysite.com/client123/app http://mysite.com/clientxyz/app

I need to write an iRule to redirect “clientxyz” to an alternate location. The below basic iRule does not match “clientxyz” and I end up in pool.2 instead of pool.1. However if I change the switch statement to “/clientxyz*” it works fine. There are client directories that will be named very similar, and just to be on the safe side we do not want to allow any possibility of a wildcard match. I researched special characters for both iRules and TCL and “” is not listed as one of them. I tried escaping it anyways with a “\” but it made no difference. Please advise. PS - I have no idea why the “” is there to begin with; but in the short term it cannot be removed.

when HTTP_REQUEST { switch -glob [HTTP::uri] { “/clientxyz/*” { pool pool.1 } default { pool pool.2

} } }

Have you tried switch -exact ?

Hi Wallst,

its not possible to parse on this specific information. Well, its not a fault of your iRule or even F5, its more a thing of the underlying HTTP standart.

In the URI world the Hash-Sign () is called a “Fragment” and is completely suppressed from sending by every browser.

scheme:[//[user:password@]host[:port]][/]path[?query][fragment]

So everthing after the Hash-Sign never hits the wire and therefor never reaches your F5.

For more information refer to: https://en.wikipedia.org/wiki/Fragment_identifierBasics

Note: The Basics fragment of the Wiki site causes your Browser to jump to the section containing the code ‘id=“Basics”’

But you may want to change your iRule to exclude everything after the Hash-Sign. It would allow you to select the [pool] accordingly…

when HTTP_REQUEST { 
    switch -glob [HTTP::uri] { 
        "/clientxyz*" { pool pool.1 } 
        default { pool pool.2 } 
    }
}

Cheers, Kai

If the “” is not seen by the F5, should I be able to ignore it as far as matching goes in the iRule? Also, in the basic iRule I pasted, what is the proper location to insert a “log” statement. I tried to capture the $URI value, but not seeng it written to ltm (log local0 “$URI”).

Hi Wallst32,

if you have conflicting names for /clientxyz*, then you have to use the more accurate condition of /clientxyz.

But keep in mind that the page may request other content right after (e.g. CSS, JScript, grafics, etc.). So you may need to forward some additional [HTTP::uri]'s to the [pool pool.1]…

The logging part is quite easy to handle. You can basically put every readable iRule command directly into the log statement..

when HTTP_REQUEST { 
    log -noname local0.debug "Client = [IP::client_addr] has requested the URI = [HTTP::uri]"
    switch -glob -- [string tolower [HTTP::uri]] { 
        "/clientxyz" {
            log -noname local0.debug "URI = [HTTP::uri] is getting forwarded to pool.1"
            pool pool.1 
        } 
        default { 
            log -noname local0.debug "URI = [HTTP::uri] is getting forwarded to pool.2"
            pool pool.2 
        } 
    }
}

Note: I’ve changed your code to ignore the case using a [string tolower] command and included an -- to explicitly mark the end of the -option section. Both changes would make the [switch] condition more robust…

Cheers, Kai