I use the following code (a server verticle listening on port 80):
router.routeWithRegex(".*").handler(routingContext -> {
String absoluteURI = routingContext.request().absoluteURI();
String redirectUrl = DEFAULT_URL;
if (absoluteURI.startsWith("http://")) {
redirectUrl = "https" + absoluteURI.substring(4);
}
HttpServerResponse response = routingContext.response();
response.setStatusCode(HttpURLConnection.HTTP_MOVED_TEMP);
response.putHeader("Location", redirectUrl);
response.end;
}
It redirects all clients requesting "
http://mydomain.com/mypath" (implicit port) to the correspondong SSL server (https + port 443)
But it does not work for clients requesting "
http://mydomain.com:80/mypath" (explicit path).
It looks to me that browsers do not change explicit ports when redirecting to a https URL.
How to redirect clients correctly to SSL which works for both cases (explicit and implicit ports)?