Forum Discussion

dp_119903's avatar
dp_119903
Icon for Cirrostratus rankCirrostratus
Jan 04, 2017
Solved

Redirect Rewrite not working - how write an irule to redirect non-standard port

Simple port change, just not sure which path to take. I have a virtual server that is listening on 443. It redirects to a server on the backside that is listening on http (not SSL) via port 10108....
  • dp_119903's avatar
    Jan 04, 2017

    Well, enough digging and I guess you can answer your own question.

    I found that a stream profile was needed, I presume b/c it wasn't actually a redirect but I'm not entirely certain. With that said, I applied an empty stream profile and the following irule:

    
    when HTTP_REQUEST {
         tell server not to compress response
        HTTP::header remove Accept-Encoding
    
         disable STREAM for request flow
        STREAM::disable
    }
    when HTTP_RESPONSE {
         catch and replace redirect headers
        if { [HTTP::header exists Location] } {
            HTTP::header replace Location [string map {"http://" "https://"} [HTTP::header 
    Location]]
        }
    
         only look at text data
        if {[HTTP::header "Host"] contains "10108" }  { } {
    
             create a STREAM expression to replace any http:// with https://
            STREAM::expression {@http://example.com:10108@https://example.com@}
    
             enable STREAM
            STREAM::enable
        }
    }
    

    ...and it works like a champ.