Forum Discussion

Joe_Pena's avatar
Joe_Pena
Icon for Nimbostratus rankNimbostratus
Feb 06, 2018

redirecting hostname to proper URI path

I was asked to create a redirect whenever a client types this into their browser, omsqa.domain.com redirect it to http://omsqa.tbccorp.com/isccs/isccs/login.do. My irule seems to perform the redirect but the page doesn't load, I get error redirecting occur in firefox. If i use fiddle i can see it perform the 302 redirect. I'm not sure what else to look at. If I remove the irule from the VS, and go directly to the full URL (http://omsqa.tbccorp.com/isccs/isccs/login.do) it works fine. Please help

 

when HTTP_REQUEST {

 

switch -glob [string tolower [HTTP::host]] {

 

"omsqa.tbccorp.com" - {

 

HTTP::redirect ";

 

}

 

}

 

}

 

6 Replies

  • Hi there,

    try this instead:

    when HTTP_REQUEST {
        if { [HTTP::uri] equals "/"}{
            HTTP::uri "/isccs/isccs/login.do"
        }
    }
    
  • when HTTP_REQUEST {
    if {[string tolower [HTTP::host]] eq "omsqa.tbccorp.com" && [HTTP::uri] eq "/"} { 
        HTTP::redirect "http://omsqa.tbccorp.com/isccs/isccs/login.do"
    }
    }
    
  • as the previous user mentioned before, you don't need a redirect: the host is the same.

     

    HTTP::uri should do the trick....

     

    • Stanislas_Piro2's avatar
      Stanislas_Piro2
      Icon for Cumulonimbus rankCumulonimbus

      rewriting HTTP::uri is not the best solution, mostly when path folder is different.

       

      If server answers with relative path links in content, browser can request wrong URI next.

       

  • AMG provided the best solution. I also recommend to use HTTP::path instead of HTTP::uri in condition and to redirect to relative URI / absolute path (beginning with /) instead of absolute URL:

    when HTTP_REQUEST {
        if {[string tolower [HTTP::host]] eq "omsqa.tbccorp.com" && [HTTP::path] eq "/"} { 
            HTTP::redirect "/isccs/isccs/login.do"
        }
    }