diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php
index f68ab1e5f2ce3498062950850d47048469fb01f6..78be4eeed5e25cd6d6211fd955b050985eaf0c98 100644
--- a/lib/SimpleSAML/Utilities.php
+++ b/lib/SimpleSAML/Utilities.php
@@ -212,7 +212,7 @@ class SimpleSAML_Utilities {
 		$globalConfig = SimpleSAML_Configuration::getInstance();
 		$baseURL = $globalConfig->getString('baseurlpath', 'simplesaml/');
 		
-		if (preg_match('#^https?://([^/]*)/(.*)/$#D', $baseURL, $matches)) {
+		if (preg_match('#^https?://.*/$#D', $baseURL, $matches)) {
 			/* full url in baseurlpath, override local server values */
 			return $baseURL;
 		} elseif (