diff --git a/lib/SimpleSAML/Auth/Simple.php b/lib/SimpleSAML/Auth/Simple.php
index da0881d48dbdaea9a695a2d7e3fc480792a641e8..33fc4e552aa71074c4ebf217e754c73be47eb71b 100644
--- a/lib/SimpleSAML/Auth/Simple.php
+++ b/lib/SimpleSAML/Auth/Simple.php
@@ -110,7 +110,7 @@ class SimpleSAML_Auth_Simple {
 		} else if (array_key_exists('ReturnCallback', $params)) {
 			$returnTo = (array)$params['ReturnCallback'];
 		} else {
-			$returnTo = SimpleSAML_Utilities::selfURL();
+			$returnTo = \SimpleSAML\Utils\HTTP::getSelfURL();
 		}
 
 		if (is_string($returnTo) && $keepPost && $_SERVER['REQUEST_METHOD'] === 'POST') {
@@ -159,7 +159,7 @@ class SimpleSAML_Auth_Simple {
 		assert('is_array($params) || is_string($params) || is_null($params)');
 
 		if ($params === NULL) {
-			$params = SimpleSAML_Utilities::selfURL();
+			$params = \SimpleSAML\Utils\HTTP::getSelfURL();
 		}
 
 		if (is_string($params)) {
@@ -290,7 +290,7 @@ class SimpleSAML_Auth_Simple {
 		assert('is_null($returnTo) || is_string($returnTo)');
 
 		if ($returnTo === NULL) {
-			$returnTo = SimpleSAML_Utilities::selfURL();
+			$returnTo = \SimpleSAML\Utils\HTTP::getSelfURL();
 		}
 
 		$login = SimpleSAML_Module::getModuleURL('core/as_login.php', array(
@@ -313,7 +313,7 @@ class SimpleSAML_Auth_Simple {
 		assert('is_null($returnTo) || is_string($returnTo)');
 
 		if ($returnTo === NULL) {
-			$returnTo = SimpleSAML_Utilities::selfURL();
+			$returnTo = \SimpleSAML\Utils\HTTP::getSelfURL();
 		}
 
 		$logout = SimpleSAML_Module::getModuleURL('core/as_logout.php', array(
diff --git a/lib/SimpleSAML/Error/NotFound.php b/lib/SimpleSAML/Error/NotFound.php
index cb868e8ac54a2631950e2faccbf37bb4b39d46e6..251ff1909424f0479aea64ae59f135c1c6e27100 100644
--- a/lib/SimpleSAML/Error/NotFound.php
+++ b/lib/SimpleSAML/Error/NotFound.php
@@ -27,7 +27,7 @@ class SimpleSAML_Error_NotFound extends SimpleSAML_Error_Error {
 
 		assert('is_null($reason) || is_string($reason)');
 
-		$url = SimpleSAML_Utilities::selfURL();
+		$url = \SimpleSAML\Utils\HTTP::getSelfURL();
 
 		if($reason === NULL) {
 			parent::__construct(array('NOTFOUND', '%URL%' => $url));
diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php
index b6aaa95e4d95b2c396ec16ad9208010056380e79..44f2ff14c8257c95171c7332057b02b94b99a847 100644
--- a/lib/SimpleSAML/Utilities.php
+++ b/lib/SimpleSAML/Utilities.php
@@ -96,20 +96,11 @@ class SimpleSAML_Utilities {
 	}
 
 
+    /**
+     * @deprecated This method will be removed in SSP 2.0. Please use SimpleSAML\Utils\HTTP::getSelfURL() instead.
+     */
 	public static function selfURL() {
-
-		$selfURLhost = self::selfURLhost();
-
-		$requestURI = $_SERVER['REQUEST_URI'];
-		if ($requestURI[0] !== '/') {
-			/* We probably have a URL of the form: http://server/. */
-			if (preg_match('#^https?://[^/]*(/.*)#i', $requestURI, $matches)) {
-				$requestURI = $matches[1];
-			}
-		}
-
-		return $selfURLhost . $requestURI;
-
+		return \SimpleSAML\Utils\HTTP::getSelfURL();
 	}
 
 
diff --git a/lib/SimpleSAML/Utils/Auth.php b/lib/SimpleSAML/Utils/Auth.php
index 48dd8ffe0b0ec5928d9079b573e619779a862732..16aec172f232da7ae392b91b1aab3567940c2ba6 100644
--- a/lib/SimpleSAML/Utils/Auth.php
+++ b/lib/SimpleSAML/Utils/Auth.php
@@ -21,7 +21,7 @@ class Auth
         assert('is_string($returnTo) || is_null($returnTo)');
 
         if ($returnTo === null) {
-            $returnTo = \SimpleSAML_Utilities::selfURL();
+            $returnTo = \SimpleSAML\Utils\HTTP::getSelfURL();
         }
 
         return \SimpleSAML_Module::getModuleURL('core/login-admin.php', array('ReturnTo' => $returnTo));
diff --git a/lib/SimpleSAML/Utils/HTTP.php b/lib/SimpleSAML/Utils/HTTP.php
index 1d68285351851771246fb9088ef419c058a02407..eed837a28dc6cc3e83eb282d8624cfeaf48a5e38 100644
--- a/lib/SimpleSAML/Utils/HTTP.php
+++ b/lib/SimpleSAML/Utils/HTTP.php
@@ -371,6 +371,28 @@ class HTTP
     }
 
 
+    /**
+     * Retrieve the current URL.
+     *
+     * @return string The current URL.
+     *
+     * @author Andreas Solberg, UNINETT AS <andreas.solberg@uninett.no>
+     * @author Olav Morken, UNINETT AS <olav.morken@uninett.no>
+     */
+    public static function getSelfURL()
+    {
+        $selfURLhost = self::getSelfURLHost();
+        $requestURI = $_SERVER['REQUEST_URI'];
+        if ($requestURI[0] !== '/') {
+            // we probably have a URL of the form: http://server/
+            if (preg_match('#^https?://[^/]*(/.*)#i', $requestURI, $matches)) {
+                $requestURI = $matches[1];
+            }
+        }
+        return $selfURLhost.$requestURI;
+    }
+
+
     /**
      * Retrieve a URL containing the protocol, the current host and optionally, the port number.
      *
diff --git a/modules/authX509/templates/X509error.php b/modules/authX509/templates/X509error.php
index 90e2dbd54ab47267864704d31986b166ade98534..c55ae65c4821e8e64fc6a5159e736d6d094e1a5f 100644
--- a/modules/authX509/templates/X509error.php
+++ b/modules/authX509/templates/X509error.php
@@ -21,7 +21,7 @@ if ($this->data['errorcode'] !== NULL) {
 
 	<p><?php echo $this->t('{authX509:X509error:certificate_text}'); ?></p>
 
-	<a href="<?php echo htmlspecialchars(SimpleSAML_Utilities::selfURL()); ?>">
+	<a href="<?php echo htmlspecialchars(\SimpleSAML\Utils\HTTP::getSelfURL()); ?>">
 		<?php echo $this->t('{login:login_button}'); ?>
 	</a>
 
diff --git a/modules/consentAdmin/templates/consentadmin.php b/modules/consentAdmin/templates/consentadmin.php
index aac3c499ff3083d6941d3421f9ea0e9b1dfea72e..496d5145280279baae13a1059e20010d395d70e7 100644
--- a/modules/consentAdmin/templates/consentadmin.php
+++ b/modules/consentAdmin/templates/consentadmin.php
@@ -131,6 +131,6 @@ TRSTART;
 		
 		<h2>Logout</h2>
 
-			<p><a href="<?php echo SimpleSAML_Utilities::selfURL() . '?logout'; ?>">Logout</a></p>
+			<p><a href="<?php echo \SimpleSAML\Utils\HTTP::getSelfURL() . '?logout'; ?>">Logout</a></p>
 		
 <?php $this->includeAtTemplateBase('includes/footer.php');
diff --git a/modules/cron/www/cron.php b/modules/cron/www/cron.php
index 3180ca5d523899fe21b03f5a2964e0b6b89b3f9f..682c2420564eec805116acc8c662e52917c0c971 100644
--- a/modules/cron/www/cron.php
+++ b/modules/cron/www/cron.php
@@ -22,7 +22,7 @@ $croninfo = array(
 	'summary' => &$summary,
 	'tag' => $_REQUEST['tag'],
 );
-$url = SimpleSAML_Utilities::selfURL();
+$url = \SimpleSAML\Utils\HTTP::getSelfURL();
 $time = date(DATE_RFC822);
 
 SimpleSAML_Module::callHooks('cron', $croninfo);
diff --git a/modules/oauth/www/authorize.php b/modules/oauth/www/authorize.php
index 523670ecf148be54873fa8d3797638c1fee1e60a..17392ad73138aed811e74ec629cb5ab332fda179 100644
--- a/modules/oauth/www/authorize.php
+++ b/modules/oauth/www/authorize.php
@@ -30,7 +30,7 @@ try {
 
 	$as = $oauthconfig->getString('auth');
 	if (!$session->isValid($as)) {
-		SimpleSAML_Auth_Default::initLogin($as, SimpleSAML_Utilities::selfURL());
+		SimpleSAML_Auth_Default::initLogin($as, \SimpleSAML\Utils\HTTP::getSelfURL());
 	}
 
 
@@ -40,7 +40,7 @@ try {
 		$t = new SimpleSAML_XHTML_Template($config, 'oauth:consent.php');
 		$t->data['header'] = '{status:header_saml20_sp}';
 		$t->data['consumer'] = $consumer;	// array containint {name, description, key, secret, owner} keys
-		$t->data['urlAgree'] = \SimpleSAML\Utils\HTTP::addURLParameters(SimpleSAML_Utilities::selfURL(), array("consent" => "yes"));
+		$t->data['urlAgree'] = \SimpleSAML\Utils\HTTP::addURLParameters(\SimpleSAML\Utils\HTTP::getSelfURL(), array("consent" => "yes"));
 		$t->data['logouturl'] = SimpleSAML_Utilities::selfURLNoQuery() . '?logout';
 	
 		$t->show();
diff --git a/modules/oauth/www/registry.edit.php b/modules/oauth/www/registry.edit.php
index 1ce979ae40f33db5940032184a897f8eadba57fa..555e77b678e43a55ba6e96765f27bf68de372158 100644
--- a/modules/oauth/www/registry.edit.php
+++ b/modules/oauth/www/registry.edit.php
@@ -17,7 +17,7 @@ if ($session->isValid($authsource)) {
 		throw new Exception('User ID is missing');
 	$userid = $attributes[$useridattr][0];
 } else {
-	SimpleSAML_Auth_Default::initLogin($authsource, SimpleSAML_Utilities::selfURL());
+	SimpleSAML_Auth_Default::initLogin($authsource, \SimpleSAML\Utils\HTTP::getSelfURL());
 }
 
 function requireOwnership($entry, $userid) {
diff --git a/modules/oauth/www/registry.php b/modules/oauth/www/registry.php
index dfea92831f8e6fab0a1a0624ea880fe9459ebd36..bd36ac448ee17454e8c68f94dfd1b86f3f1c59b6 100644
--- a/modules/oauth/www/registry.php
+++ b/modules/oauth/www/registry.php
@@ -17,7 +17,7 @@ if ($session->isValid($authsource)) {
 		throw new Exception('User ID is missing');
 	$userid = $attributes[$useridattr][0];
 } else {
-	SimpleSAML_Auth_Default::initLogin($authsource, SimpleSAML_Utilities::selfURL());
+	SimpleSAML_Auth_Default::initLogin($authsource, \SimpleSAML\Utils\HTTP::getSelfURL());
 }
 
 function requireOwnership($entry, $userid) {
diff --git a/modules/saml/lib/IdP/SAML1.php b/modules/saml/lib/IdP/SAML1.php
index 1d7b02a67c83eb1971414617be399ae9121da8b0..2cd520becdace56ee5667968f17365b8830aae6d 100644
--- a/modules/saml/lib/IdP/SAML1.php
+++ b/modules/saml/lib/IdP/SAML1.php
@@ -69,7 +69,7 @@ class sspmod_saml_IdP_SAML1 {
 				 * Less than five seconds has passed since we were
 				 * here the last time. Cookies are probably disabled.
 				 */
-				SimpleSAML_Utilities::checkCookie(SimpleSAML_Utilities::selfURL());
+				SimpleSAML_Utilities::checkCookie(\SimpleSAML\Utils\HTTP::getSelfURL());
 			}
 		}
 
@@ -116,7 +116,7 @@ class sspmod_saml_IdP_SAML1 {
 		));
 
 		$sessionLostURL = \SimpleSAML\Utils\HTTP::addURLParameters(
-			SimpleSAML_Utilities::selfURL(),
+            \SimpleSAML\Utils\HTTP::getSelfURL(),
 			array('cookieTime' => time()));
 
 		$state = array(
diff --git a/modules/saml/lib/IdP/SAML2.php b/modules/saml/lib/IdP/SAML2.php
index a6bf33a4c8e793af3315346c3907fea00ca17746..e8e5a8b8d972c692ead4237397af05885ec290df 100644
--- a/modules/saml/lib/IdP/SAML2.php
+++ b/modules/saml/lib/IdP/SAML2.php
@@ -247,7 +247,7 @@ class sspmod_saml_IdP_SAML2 {
 					 * Less than five seconds has passed since we were
 					 * here the last time. Cookies are probably disabled.
 					 */
-					SimpleSAML_Utilities::checkCookie(SimpleSAML_Utilities::selfURL());
+					SimpleSAML_Utilities::checkCookie(\SimpleSAML\Utils\HTTP::getSelfURL());
 				}
 			}
 
diff --git a/templates/includes/header.php b/templates/includes/header.php
index 10f75765b7a61148edb2092aceb3316071078d17..03f19535882d552f662db915aa90ce1d21be24b9 100644
--- a/templates/includes/header.php
+++ b/templates/includes/header.php
@@ -186,7 +186,7 @@ if($onLoad !== '') {
 				if ($current) {
 					$textarray[] = $langnames[$lang];
 				} else {
-					$textarray[] = '<a href="' . htmlspecialchars(\SimpleSAML\Utils\HTTP::addURLParameters(SimpleSAML_Utilities::selfURL(), array($this->languageParameterName => $lang))) . '">' .
+					$textarray[] = '<a href="' . htmlspecialchars(\SimpleSAML\Utils\HTTP::addURLParameters(\SimpleSAML\Utils\HTTP::getSelfURL(), array($this->languageParameterName => $lang))) . '">' .
 						$langnames[$lang] . '</a>';
 				}
 			}
diff --git a/www/admin/hostnames.php b/www/admin/hostnames.php
index f8ef96dbd9d8972442c22d3360a2b6abdce8e695..142cf16bf90082cb2fac146657db7832dcd7682b 100644
--- a/www/admin/hostnames.php
+++ b/www/admin/hostnames.php
@@ -22,7 +22,7 @@ $attributes['Utilities_selfURLhost()'] = array(\SimpleSAML\Utils\HTTP::getSelfUR
 $attributes['Utilities_selfURLNoQuery()'] = array(SimpleSAML_Utilities::selfURLNoQuery());
 $attributes['Utilities_getSelfHostWithPath()'] = array(\SimpleSAML\Utils\HTTP::getSelfHostWithPath());
 $attributes['Utilities_getFirstPathElement()'] = array(\SimpleSAML\Utils\HTTP::getFirstPathElement());
-$attributes['Utilities_selfURL()'] = array(SimpleSAML_Utilities::selfURL());
+$attributes['Utilities_selfURL()'] = array(\SimpleSAML\Utils\HTTP::getSelfURL());
 
 $et = new SimpleSAML_XHTML_Template($config, 'hostnames.php');
 
diff --git a/www/authmemcookie.php b/www/authmemcookie.php
index 00cf2e65661c0dcf30395a5c058925d19b4b632e..96e318ca428763be384758930dccc48075a11b81 100644
--- a/www/authmemcookie.php
+++ b/www/authmemcookie.php
@@ -93,7 +93,7 @@ try {
 	$session->registerLogoutHandler($sourceId, 'SimpleSAML_AuthMemCookie', 'logoutHandler');
 
 	/* Redirect the user back to this page to signal that the login is completed. */
-	SimpleSAML_Utilities::redirectTrustedURL(SimpleSAML_Utilities::selfURL());
+	SimpleSAML_Utilities::redirectTrustedURL(\SimpleSAML\Utils\HTTP::getSelfURL());
 } catch(Exception $e) {
 	throw new SimpleSAML_Error_Error('CONFIG', $e);
 }