I have a web application that is running on a non-standard port. We need to have SSL on it. I applied the client certificate and https works fine, but if we enter http we get a page cannot be displayed.
Can I write a rule to redirect any http requests to this host on this port to https?
If the request can be HTTP or HTTPS on the same port, you can track whether there was a client SSL handshake using the CLIENTSSL_HANDSHAKE event and only send a redirect for requests which didn’t initiate a n SSL handshake. Because the port stays the same, you can redirect to the same host (including the port) and URI.
when CLIENT_ACCEPTED {
Set a variable to track whether this is an HTTPS request
set https 0
}
when CLIENTSSL_HANDSHAKE {
There was a client side SSL handshake, so update the variable
set https 1
}
when HTTP_REQUEST {
If it's not an HTTPS connection, send a redirect
if {not ($https)}{
HTTP::redirect https://[HTTP::host][HTTP::uri]
}
}
Do you have non-SSL enabled on the client SSL profile? This will be required in order to issue a redirect on a non-SSL request.
If it still doesn’t work, can you try this version with logging:
when CLIENT_ACCEPTED {
log local0. "[IP::client_addr]:[TCP::client_port]: new connection to [IP::local_port]:[TCP::local_port]. https 0"
Set a variable to track whether this is an HTTPS request
set https 0
}
when CLIENTSSL_HANDSHAKE {
log local0. "[IP::client_addr]:[TCP::client_port]: new connection to [IP::local_port]:[TCP::local_port]. https 1"
There was a client side SSL handshake, so update the variable
set https 1
}
when HTTP_REQUEST {
If it's not an HTTPS connection, send a redirect
if {not ($https)}{
log local0. "[IP::client_addr]:[TCP::client_port]: new connection to [IP::local_port]:[TCP::local_port] redirecting http"
HTTP::redirect https://[HTTP::host][HTTP::uri]
}
}
I have the same requirement, if user access the URL with HTTPS, no change in URL. If user access the URLwith HTTP, should redirect to https, I am also using non-standard port URLS.