diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php
index e9587ccc52969c066cc244fee642ea6c5efcb62a..2a4a9165c1eb58fe81ecbe7cffb6fc3222043ce6 100644
--- a/lib/SimpleSAML/Utilities.php
+++ b/lib/SimpleSAML/Utilities.php
@@ -59,7 +59,11 @@ class SimpleSAML_Utilities {
 
 		if(strstr($currenthost, ":")) {
 				$currenthostdecomposed = explode(":", $currenthost);
-				$currenthost = $currenthostdecomposed[0];
+				$port = array_pop($currenthostdecomposed);
+				if (!is_numeric($port)) {
+					array_push($currenthostdecomposed, $port);
+                }
+                $currenthost = implode($currenthostdecomposed, ":");
 		}
 		return $currenthost;