diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php
index 11bf5e30d83db5201244ab17fa513b12fd392dff..0cefb473b138765b2b4334844dd197d2e70cd8d6 100644
--- a/lib/SimpleSAML/Utilities.php
+++ b/lib/SimpleSAML/Utilities.php
@@ -28,8 +28,9 @@ class SimpleSAML_Utilities {
 	 */
 	public static function getSelfProtocol() {
 		$s = empty($_SERVER["HTTPS"]) ? ''
-			: ($_SERVER["HTTPS"] == "on") ? "s"
-			: "";
+			: ($_SERVER["HTTPS"] == "on") ? 's'
+			: '';
+		if ( empty($_SERVER["HTTPS"]) && $_SERVER["SERVER_PORT"] == 443) $s = 's';
 		$protocol = self::strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s;
 		return $protocol;
 	}