Forum Discussion

risgro_77522's avatar
risgro_77522
Icon for Nimbostratus rankNimbostratus
May 11, 2015

URL needs to be in certain case letters

Hello,

In the URL/application, "WebCenter" is case-sensitive. So if a client hits:

    https://qweb.sys.com/webcenter/default or
    https://qweb.sys.com/Webcenter/default or
    https://qweb.sys.com/WEBCENTER/default or 
`


any other upper and lower case mixture of the word "webcenter", we always want the client to be redirected to:

`    https://qweb.sys.com/WebCenter/default with a capital "W" and a capital "C".

Any suggestions on a iRule to handle this?

Thank you, Rich

10 Replies

  • You can try something like this:

    when HTTP_REQUEST {
        if { [HTTP::uri] equals "WebCenter" } {
             URL is correct case, do nothing"
        }
        elseif { string tolower [HTTP::uri] equals "webcenter" }
            HTTP::redirect "https://qweb.sys.com/WebCenter/default with a capital W and a capital C"
        }
    }
    

    Or, do you want to just fix it for them?

    • Robert_Luechte2's avatar
      Robert_Luechte2
      Icon for Cirrus rankCirrus
      Sorry, you should probably use starts_with instead of equals in the if statements.
  • You can try something like this:

    when HTTP_REQUEST {
        if { [HTTP::uri] equals "WebCenter" } {
             URL is correct case, do nothing"
        }
        elseif { string tolower [HTTP::uri] equals "webcenter" }
            HTTP::redirect "https://qweb.sys.com/WebCenter/default with a capital W and a capital C"
        }
    }
    

    Or, do you want to just fix it for them?

    • Robert_Luechte1's avatar
      Robert_Luechte1
      Icon for Nimbostratus rankNimbostratus
      Sorry, you should probably use starts_with instead of equals in the if statements.
  • I should have read your question a little close before I responded the first time. Here is an example where the user is redirected with the proper case for WebCenter and includes the rest of the URL. I haven't actually tested this, so there could be some syntax issues.

    when HTTP_REQUEST {
        if { [HTTP::uri] starts_with "WebCenter" } {
             URL is correct case, do nothing"
        }
        elseif { string tolower [HTTP::uri] starts_with "webcenter" }
             redirect user to the proper case, including the remainter of the URI.
             The value 10 in the substring command should be the first character of the rest of the URI.
            HTTP::redirect "https://qweb.sys.com/WebCenter/[substr [HTTP::uri] 10]"
        }
    }
    
  • Please try this. Hope it will work as per your plan.

        when HTTP_REQUEST { 
              if { ( [string tolower [HTTP::uri]] starts_with "/webcenter" ) } { 
                    HTTP::redirect https://qweb.sys.com/WebCenter/default
                  } 
                }
    
  • Arie's avatar
    Arie
    Icon for Altostratus rankAltostratus

    Am I correct to assume that the origin web server needs to receive the request in the proper case, but that it doesn't really matter from a client-perspective?

     

    If so, I would recommend re-writing the URI regardless of the case of the request. Redirecting does the trick, but it requires another request (i.e. increased overhead) and isn't as clean as a re-rewrite in my opinion. Something like this should do the trick if you want to re-write the request transparently:

     

    when HTTP_REQUEST {
    
        if { [string tolower [HTTP::path]] starts_with "/webcenter/" } {
    
            HTTP::uri "[string map -nocase { "/webcenter/" "/WebCenter/" } [HTTP::path]]"
    
        }
    
    }

    (Note - I haven't tested the above code so I hope I didn't make any typos/omissions.)

     

  • this is just one of examples.

     configuration
    
    root@(ve11c)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm virtual bar
    ltm virtual bar {
        destination 172.28.24.10:80
        ip-protocol tcp
        mask 255.255.255.255
        pool foo
        profiles {
            http { }
            tcp { }
        }
        rules {
            qux
        }
        source 0.0.0.0/0
        source-address-translation {
            type automap
        }
        vs-index 4
    }
    root@(ve11c)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm rule qux
    ltm rule qux {
        when HTTP_REQUEST {
      switch -glob [HTTP::uri] {
        "/[wW]ebcenter/default" -
        "/WEBCENTER/default" {
           Do nothing
        }
        "/[wW][eE][bB][cC][eE][nN][tT][eE][rR]/default" {
          HTTP::redirect "http://[HTTP::host]/WebCenter/default"
        }
        default {
           Do nothing
        }
      }
    }
    }
    
     test
    
    [root@ve11c:Active:In Sync] config  curl -I http://qweb.sys.com/webcenter/default
    HTTP/1.1 404 Not Found
    Date: Sun, 24 May 2015 14:18:07 GMT
    Server: Apache/2.2.3 (CentOS)
    Last-Modified: Sun, 09 Feb 2014 08:39:51 GMT
    ETag: "41879c-59-2a9c23c0"
    Accept-Ranges: bytes
    Content-Length: 89
    Content-Type: text/html; charset=UTF-8
    
    [root@ve11c:Active:In Sync] config  curl -I http://qweb.sys.com/Webcenter/default
    HTTP/1.1 404 Not Found
    Date: Sun, 24 May 2015 14:18:13 GMT
    Server: Apache/2.2.3 (CentOS)
    Last-Modified: Sun, 09 Feb 2014 08:39:51 GMT
    ETag: "41879c-59-2a9c23c0"
    Accept-Ranges: bytes
    Content-Length: 89
    Content-Type: text/html; charset=UTF-8
    
    [root@ve11c:Active:In Sync] config  curl -I http://qweb.sys.com/WEBCENTER/default
    HTTP/1.1 404 Not Found
    Date: Sun, 24 May 2015 14:18:32 GMT
    Server: Apache/2.2.3 (CentOS)
    Last-Modified: Sun, 09 Feb 2014 08:39:51 GMT
    ETag: "41879c-59-2a9c23c0"
    Accept-Ranges: bytes
    Content-Length: 89
    Content-Type: text/html; charset=UTF-8
    
    [root@ve11c:Active:In Sync] config  curl -I http://qweb.sys.com/WeBcEnTeR/default
    HTTP/1.0 302 Found
    Location: http://qweb.sys.com/WebCenter/default
    Server: BigIP
    Connection: Keep-Alive
    Content-Length: 0