diff --git a/lib/SimpleSAML/Utils/HTTP.php b/lib/SimpleSAML/Utils/HTTP.php
index 9568d74af38b989542d452cd6e3caf873911c6ab..fd01223d794b57d42d9bc178309002425276a2ad 100644
--- a/lib/SimpleSAML/Utils/HTTP.php
+++ b/lib/SimpleSAML/Utils/HTTP.php
@@ -780,14 +780,12 @@ class HTTP
              * It doesn't matter which one of those cases we have. We just know we can't apply our base URL to the
              * current URI, so we need to build it back from the PHP environment.
              */
-            $https = self::getServerHTTPS();
             $protocol = 'http';
-            $protocol .= $https ? 's' : '';
+            $protocol .= (self::getServerHTTPS()) ? 's' : '';
             $protocol .= '://';
 
             $hostname = self::getServerHost();
             $port = self::getServerPort();
-            $port = ($https && $port !== ':443') || (!$https && $port !== ':80') ? $port : '';
             return $protocol.$hostname.$port.$_SERVER['REQUEST_URI'];
         }