For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

aschi's avatar
aschi
Icon for Nimbostratus rankNimbostratus
Mar 13, 2013

Just Part of the url tolower

Hi

I searched the web and forum on ho to change some parts ot the url but wasn't successfull.

I need a iRule that just changes the bold part in the following examples.

www.domain.ch/URI1/(S(o5flruacyziex445hrvlk355))/index.aspx

www.domain.ch/uri/(S(o5flruacyziex445hrvlk355))/index.aspx

I tried with regex scan ans string match but never go it running.

It was easy change the complete uri or host tolower but not for just a part in the middle.

Which Method should I use?

In the following Article (https://devcentral.f5.com/wiki/iRul...rCase.ashx) is also just one Part tolower but it's not what i'm looking for.

Original request: http://www.example.com/myDirectory/Index.html?Param1=Value1&Param2=Value2

Modified request: http://www.example.com/mydirectory/index.html?Param1=Value1&Param2=Value2

Any Help is appreciated,

Best Regards,

Roger

3 Replies

  • do you want to lower whole HTTP::path string (e.g. /myDirectory/Index.html) or only the first directory (e.g. /myDirectory/)?

     

     

    whole HTTP::path string

     

     

    [root@ve10:Active] config b rule myrule list

     

    rule myrule {

     

    when HTTP_REQUEST {

     

    if { [HTTP::query] ne "" } {

     

    HTTP::redirect " tolower [HTTP::path]]?[HTTP::query]"

     

    } else {

     

    HTTP::redirect " tolower [HTTP::path]]"

     

    }

     

    }

     

    }

     

     

    [root@ve10:Active] config curl -I 'http://www.example.com/myDirectory/Index.html?Param1=Value1&Param2=Value2'

     

    HTTP/1.0 302 Found

     

    Location: http://www.example.com/mydirectory/...am2=Value2

     

    Server: BigIP

     

    Connection: Keep-Alive

     

    Content-Length: 0

     

     

    the first directory

     

     

    [root@ve10:Active] config b rule myrule list

     

    rule myrule {

     

    when HTTP_REQUEST {

     

    if { [scan [HTTP::path] {/%[^/]} str] == 1 } {

     

    HTTP::redirect " map [list /${str}/ /[string tolower $str]/] [HTTP::uri]]"

     

    }

     

    }

     

    }

     

     

    [root@ve10:Active] config curl -I 'http://www.example.com/myDirectory/Index.html?Param1=Value1&Param2=Value2'

     

    HTTP/1.0 302 Found

     

    Location: http://www.example.com/mydirectory/...am2=Value2

     

    Server: BigIP

     

    Connection: Keep-Alive

     

    Content-Length: 0

     

     

  • I've not been able to test it but this might work (of course, remove the logging once it does work);

    
    Find the first element of the URI and lower it
      set stringtolower [string tolower [findstr [HTTP::uri] "/" "0" "/"]]
      log local0. "Lowered part of URI is: $stringtolower"
      Extract the rest of the URI that we don't want to lower
      set restofuri [findstr [HTTP::uri] $stringtolower "1"]
      log local0. "Remaining URI is $restofuri"
      Rebuild the URI and modify it before sending to the server
      HTTP::uri /$stringtolower/$restofuri
      log local0. "Rebuilt URI is /$stringtolower/$restofuri"
    
  • Here's two methods:

    
    when HTTP_REQUEST {
             going to split the URI on the "/" character and loop through the list
    set newURI ""
    for { set x 0 } { $x < [llength [split [HTTP::uri] "/"]] } { incr x } {
    if { $x == 1 } {
                             this is the first path - the one we want to set to lowercase
    append newURI "[string tolower [lindex [split [HTTP::uri] "/"] 1]]/" 
    } else {
    append newURI "[lindex [split [HTTP::uri] "/"] $x]/"
    }
    }
             the above append loop adds an unnecessary "/" at the end, so strip it here
    set newURI [string range $newURI 0 end-1]
    log local0. $newURI
    }
    

    or:

    effectively splitting the first part of the URI away from everything else, in one long string manipulation statement

    set newURI1 [string tolower [string range [HTTP::uri] 0 [string first "/" [HTTP::uri] 1]]][string range [HTTP::uri] [expr [string first "/" [HTTP::uri] 1] + 1] end]

    log local0. $newURI1

    Both just deal with the URI, so to get the full URL, just do this:

    [HTTP::host]$newURI