Forum Discussion

ChrisBlack_1713's avatar
ChrisBlack_1713
Icon for Nimbostratus rankNimbostratus
Sep 23, 2014

HTTP redirect not working

I have the following I rule that is working however it will not redirect uppercase /LIVELINK/LIVELINK.EXE Any ideas on how to get it to redirect both upper and lower case?

when HTTP_REQUEST {
  parse the uri 
  switch -glob [string tolower [HTTP::uri]] { 
    */livelink/livelink.exe* { 
      replace each instance of /livelink/livelink.exe with /OTCS/cs.exe in the uri 
      set replaceURI [string map [list /livelink/livelink.exe /OTCS/cs.exe] [HTTP::uri]] 
      construct the redirect 
      set cachecontrol {no-cache} 
      set pragma {no-cache} 
      set location "http://ContentServerQA.idexxi.com$replaceURI" 
      HTTP::respond 301 noserver "Location" $location "Cache-Control" $cachecontrol "Pragma" $pragma "Connection" "close" 
    } 
  }
}

12 Replies

  • This post didn't come out as I had expected. Basically I am trying to redirect. FROM http://livelinkqa.idexxi.com/livelink/livelink.exe* http://livelinkqa.idexxi.com/LIVELINK/LIVELINK.EXE* To http://ContentServerQA.idexxi.com/otcs/cs.exe
  • Hi Chris, You shouldn't need the switch. This should do it:

    when HTTP_REQUEST {
    if { [string tolower [HTTP::uri]] eq "/livelink/livelink.exe" } {
    HTTP::redirect "http://[HTTP::host]/otcs/cs.exe" } 
    }

     

    See if the above works to make sure the uri is being matched then you can add the code to create a custom response if you still need to.

    • ChrisBlack_1713's avatar
      ChrisBlack_1713
      Icon for Nimbostratus rankNimbostratus
      Would this preserve the portion of the URL after /livelink/livelink.exe
  • In the above if, probably want starts_with instead of eq, as there where * in the orginal switch.

     

    The switch should work though, not sure why it doesn't. Maybe remove the leading *, the URI should start with the / after the hostname.

     

  • when HTTP_REQUEST { if { [string tolower [HTTP::uri]] starts_with "/livelink/livelink.exe" } { HTTP::redirect "http://[HTTP::host]/otcs/cs.exe" } }

     

    Would this preserve the portion of the URL after /livelink/livelink.exe?

     

    • shaggy's avatar
      shaggy
      Icon for Nimbostratus rankNimbostratus
      what could come after /livelink/livelink.exe? is it more URL or is it a query?
    • ChrisBlack_1713's avatar
      ChrisBlack_1713
      Icon for Nimbostratus rankNimbostratus
      Yeah.... We have upgraded an application. So the hostname, virtual directory, and .exe are different however the rest of the URL is still accurate. EXAMPLE http://livelinkqa.idexxi.com/livelink/livelink.exe?func=ll&objId=598743&objAction=browse&viewType=1 RE DIRECT TO http://contentserverqa.idexxi.com/OTCS/cs.exe?func=ll&objId=598743&objAction=browse&viewType=1
    • ChrisBlack_1713's avatar
      ChrisBlack_1713
      Icon for Nimbostratus rankNimbostratus
      And the iRule I have is working just not for both cases. I have only been able to make it work for one or the other.
  • I resolved the issue by replacing [HTTP::uri]] in set replaceURI [string map [list /livelink/livelink.exe /OTCS/cs.exe] [HTTP::uri]]

     

    With [string tolower [HTTP::uri]]]

     

    Now it is redirecting both cases correctly. Thanks for your help!

     

  • OK, I see the problem, though I don't know the fix off the top of my head. Your switch matches on both cases, but your string map only matches the lower case version. Here is the output of what happens with each

    Lowercase works: GET /livelink/livelink.exe/isthisstillhere HTTP/1.0

     

    HTTP/1.0 301 Moved Permanently
    Location: http://ContentServerQA.idexxi.com/OTCS/cs.exe/isthisstillhere
    Cache-Control: no-cache
    Pragma: no-cache
    Connection: close
    Content-Length: 0
    

     

    Uppercase matches the switch, but not the string map. See the LIVELINK still in the URL

     

    GET /LIVELINK/LIVELINK.exe/thisshouldstillbethere?andthis=this HTTP/1.0
    
    HTTP/1.0 301 Moved Permanently
    Location: http://ContentServerQA.idexxi.com/LIVELINK/LIVELINK.exe/thisshouldstillbethere?andthis=this
    Cache-Control: no-cache
    Pragma: no-cache
    Connection: close
    Content-Length: 0
    

     

    maybe set HTTP::uri to a variable, string tolower that assignment. Then switch and string map on the now lowercase variable??

  • Yep, that worked. Try this:

     

    when HTTP_REQUEST {
        set myuri [string tolower [HTTP::uri]]
        switch -glob $myuri {
            */livelink/livelink.exe* {
                set replaceURI [string map [list /livelink/livelink.exe /OTCS/cs.exe] $myuri ]
                set cachecontrol {no-cache}
                set pragma {no-cache}
                set location "http://ContentServerQA.idexxi.com$replaceURI"
                HTTP::respond 301 noserver "Location" $location "Cache-Control" $cachecontrol "Pragma" $pragma "Connection" "close"
            }      
        }
    }