HTTP Redirect retaining source Port

We have an application server that, depending on the port, will provide a different applications web page. When I try to force https the port is getting removed resulting in the Default page showing and not the correct one. Is there a way to have the irule keep the port while doing the HTTP::redirect to https?

Current rule: when HTTP_REQUEST { HTTP::redirect “https://[HTTP::host][HTTP::uri]” log “[HTTP::header Connection]” TCP::close }

Example: redirected to

TIA Gordon

This what you are looking for?

Code snippet: redirect plus port chnage

You need to enable URL rewrite in your HTTP profile. Please see: K14775: Configuring an HTTP profile to rewrite URLs so that redirects from an HTTP server specify the HTTPS protocol.

If the non-HTTPS links are hard-coded in the content page, then you would need a stream profile to rewrite them.

Your example shows:

redirected to

This iRule will do that:

when CLIENT_ACCEPTED {
    TCP::collect 5
}

when CLIENT_DATA {
    switch -glob [TCP::payload] {
        "GET *" -
        "POST *" -
        "PUT *" -
        "OPTIONS *" -
        "DELETE *" -
        "TRACE *" -
        "CONNECT *" -
        "HEAD *" {
            set redirect 1
            SSL::disable clientside
        }
    }
    TCP::release
}

when HTTP_REQUEST {
    if { [info exists redirect] } {
        HTTP::respond 302 noserver Connection close Location "https://[HTTP::host][HTTP::uri]"
        unset redirect
    }
}