diff --git a/lib/SimpleSAML/Configuration.php b/lib/SimpleSAML/Configuration.php
index ac86d2d3ffbbb587757a1318550780f544d94d29..0da51db376e638333c40848268fbc9f8b5218332 100644
--- a/lib/SimpleSAML/Configuration.php
+++ b/lib/SimpleSAML/Configuration.php
@@ -358,6 +358,9 @@ class SimpleSAML_Configuration {
 		if (preg_match('#^https?://[^/]*/(.*)$#', $baseURL, $matches)) {
 			/* we have a full url, we need to strip the path */
 			return $matches[1];
+		} elseif ($baseURL === '' || $baseURL === '/') {
+			/* Root directory of site. */
+			return '';
 		} elseif (preg_match('#^/?([^/]?.*/)#D', $baseURL, $matches)) {
 			/* local path only */
 			return $matches[1];
diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php
index 7172b836425ca6a5ad3af0af65598d4278564ef6..d3c3909fb2a38a26949f335c873be4c79bc9d464 100644
--- a/lib/SimpleSAML/Utilities.php
+++ b/lib/SimpleSAML/Utilities.php
@@ -217,7 +217,8 @@ class SimpleSAML_Utilities {
 			return $baseURL;
 		} elseif (
 			(preg_match('#^/?([^/]?.*/)$#D', $baseURL, $matches)) ||
-			(preg_match('#^\*(.*)/$#D', $baseURL, $matches))) {
+			(preg_match('#^\*(.*)/$#D', $baseURL, $matches)) ||
+			($baseURL === '')) {
 			/* get server values */
 
 			if (self::getServerHTTPS()) {
@@ -228,8 +229,7 @@ class SimpleSAML_Utilities {
 
 			$hostname = self::getServerHost();
 			$port = self::getServerPort();
-			$path = $globalConfig->getBaseURL();
-			if ($path[0] != '/') $path = '/' . $path;
+			$path = '/' . $globalConfig->getBaseURL();
 
 			return $protocol.$hostname.$port.$path;
 		} else {