Forum Discussion

jonathanw84's avatar
Aug 23, 2021

iRule to Shift Entire URL Path to Lower Case

I have the following iRule in place for one of our virtual servers. Everything is working well, except some requests to the backend servers are case sensitive and need the entire path to be lowercase. For example:

 

https://dev.test.com/cdn/img/Test.png ---> https://dev.test.com/cdn/img/test.png

 

How can I achieve this with the existing iRule I have below? Thanks!

 

when CLIENT_ACCEPTED {

SSL::disable serverside

}

 

when HTTP_REQUEST {

  if { not ( [HTTP::path] ends_with "/") && not (

  [URI::basename [HTTP::uri]] contains "." ) } {

    # Append slash and keep querystring when it exists

    HTTP::respond 301 Location https://[HTTP::host][HTTP::uri]/[expr { "[URI::query [HTTP::uri]]"

    eq {} ? {} : "?[URI::query [HTTP::uri]]" }]

  }

  if { [string tolower [HTTP::uri]] starts_with "/apps" } {

    pool ProxyPass_DEV_pool_2

  }

elseif { [string tolower [HTTP::uri]] starts_with "/proxy" } {

    pool ProxyPass_DEV_pool_2

  }

  elseif { [string tolower [HTTP::uri]] starts_with "/arcgisserver" } {

    pool ProxyPass_DEV_pool_3

  }

  elseif { [string tolower [HTTP::uri]] starts_with "/aspnet" } {

    pool ProxyPass_DEV_pool_3

  }

  elseif { [string tolower [HTTP::uri]] starts_with "/api/search" } {

    SSL::enable serverside

    pool ProxyPass_DEV_pool_4

  }

  elseif { [string tolower [HTTP::uri]] starts_with "/cdn" } {

  HTTP::host docdevvm.test.com

  pool ProxyPass_DEV_pool_1

  }

  else {

    pool ProxyPass_DEV_pool_1

  }

}

5 Replies

  • oguzy's avatar
    oguzy
    Icon for Cirrostratus rankCirrostratus

    Hi,

    You can try the below one:

    when HTTP_REQUEST {
      if { [HTTP::uri] ne [string tolower [HTTP::uri]] } {
        HTTP::respond 301 noserver Location http://[HTTP::host][string tolower [HTTP::uri]]
      }
    }
  • Hello,

     

    Thanks for the response. I put that rule at the very top of my iRule under "when HTTP_REQUEST" and it looks to work, but the URI immediately reverts back to the upper case. Is this perhaps something with the backend Apache server or did I implement the iRule incorrectly?

     

    Thanks!

  • Thanks Oguzy! Still having issues with this one though :-/

     

    Any other suggestions? I need the entire url / uri to go to lower case, regardless of what the URI actually is.

  • Hi,

    Since you need to send some requests to backend as case-sensitive, you don't need to use a rediect but a rewrite funtion instead.

    Please try below iRule. Selectively add the uri which needs to be send in lowercase to backend and update iRule accordingly. I would suggest you can create new iRule and attach to the VIP. From logging, you can see if the required uri has been converted to lowercase and disable it afterwards.

    when HTTP_REQUEST {
    switch -glob [string tolower [HTTP::uri]] {
     "/cdn/img/test.png*" -
     "/cdn/img/example.png*"
     log local0. "original_uri: [HTTP::uri]"
     { 
     set new_uri "[string tolower [HTTP::uri]]"
     log local0. "new_uri: $new_uri"
     HTTP::uri $new_uri
     } default  { 
      return 
          }
        } 
     }