Forum Discussion

demmo_251289's avatar
demmo_251289
Icon for Nimbostratus rankNimbostratus
May 31, 2016
Solved

redirect for uppercase URI

Hello, I have a issue with a redirect, part of the URI is uppercase /something/somethingelse/NEW/index.html, and I'd like to redirect to lower /something/somethingelse/new/index.html

 

Now, if I do string tolower [HTTP::uri] ends_with "/new/" it works, but if I try /something/somethingelse/NEW/index.html it wouldn't redirect because the rule matches only /new/

 

How can I work this around ?

 

Thank you

 

  • If you know which part of the uri is uppercase, you can change the if condition like below :

    when HTTP_REQUEST {
        if {  [HTTP::path] contains "/NEW/"} {
            HTTP::redirect [string tolower [HTTP::uri]]
        }
    }
    

14 Replies

  • Hi,

    You can use the following irule to redirect to lower case :

    when HTTP_REQUEST {
        if {  [string tolower [HTTP::path]] contains "/new/" } {
            HTTP::redirect [string tolower [HTTP::uri]]
        }
    }
    
  • It won't work, the page won't load and I get "The page isn't redirecting properly" error. I'm using "ends_with" because nothing else work (except "start_with", but that doesn't help me either)

     

    • Yann_Desmarest's avatar
      Yann_Desmarest
      Icon for Cirrus rankCirrus
      You may hit a loop with my irule. You need to be more specific on the if condition
  • Hi,

    just few examples :

    by using ends_with "/new/ "

    -> /test/new/ - ok
    
    -> /test/new/index.html - nok
    

    By using contains "/new/" :

    -> /test/new/ - ok
    
    -> /test/new/index.html - ok
    
    • demmo_251289's avatar
      demmo_251289
      Icon for Nimbostratus rankNimbostratus
      "contains" isn't working I get "The page isn't redirecting properly" error
  • Hi,

    just few examples :

    by using ends_with "/new/ "

    -> /test/new/ - ok
    
    -> /test/new/index.html - nok
    

    By using contains "/new/" :

    -> /test/new/ - ok
    
    -> /test/new/index.html - ok
    
    • demmo_251289's avatar
      demmo_251289
      Icon for Nimbostratus rankNimbostratus
      "contains" isn't working I get "The page isn't redirecting properly" error
  • Hi,

    can you try this one, the redirect issue should be fixed :

    when HTTP_REQUEST {
        if {  [string tolower [HTTP::path]] contains "/new/" and [URI::query redirect] eq "" } {
            if { [HTTP::uri] contains "?" } {
                HTTP::redirect [string tolower [HTTP::uri]]"&redirect=1"
            } else {
                HTTP::redirect [string tolower [HTTP::uri]]"?redirect=1"
            }
        }
    }
    
  • If you know which part of the uri is uppercase, you can change the if condition like below :

    when HTTP_REQUEST {
        if {  [HTTP::path] contains "/NEW/"} {
            HTTP::redirect [string tolower [HTTP::uri]]
        }
    }
    
    • raj_paras_16233's avatar
      raj_paras_16233
      Icon for Nimbostratus rankNimbostratus

      Thanks Yann Desmarest. Thats worked for me as well. The option to vote for your answer seems to be disabled for some reason. Anyway, Thanks Heaps!

       

  • If you know which part of the uri is uppercase, you can change the if condition like below :

    when HTTP_REQUEST {
        if {  [HTTP::path] contains "/NEW/"} {
            HTTP::redirect [string tolower [HTTP::uri]]
        }
    }
    
    • raj_paras_16233's avatar
      raj_paras_16233
      Icon for Nimbostratus rankNimbostratus

      Thanks Yann Desmarest. Thats worked for me as well. The option to vote for your answer seems to be disabled for some reason. Anyway, Thanks Heaps!