Need an IRULE for HTTP and HTTPS listener on same server

I am trying to create a one Virtual server which can listen on http and https , on http it needs to redirect the request to https.

On https VS I want to do ssl bridging, I believe I need an irule for this.

when CLIENT_ACCEPTED {

set https 0

}

when CLIENTSSL_HANDSHAKE {

set https 1

}

when HTTP_REQUEST {

if {not ($https)}{

HTTP::redirect https://[HTTP::host][HTTP::uri]

}

else {

SSL::profile clientssl_profile

SSL::profile serverssl_profile

pool $Poolname

}

}

Can this irule work ? if not what changes I need here.

You can simply use the default http2https irule,

create ltm virtual APP-80-SETUP  destination 1.1.1.1:80 profiles replace-all-with { http } rules { http2https }
 
create ltm virtual APP-443-SETUP destination 1.1.1.1:443 mask 255.255.255.255 ip-protocol tcp profiles add { clientssl serverssl http-xff } pool APP-443-POOL profiles add { tcp-wan-optimized { context clientside } tcp-lan-optimized { context serverside } }

Thing is I can only have one server which listens on same port for HTTP and HTTPS, Traffic will be coming to that port only.

Here follow this article.

https://devcentral.f5.com/s/articles/handling-http-requests-on-an-https-virtual-server-31668