Index: wp-includes/pluggable.php
===================================================================
--- wp-includes/pluggable.php	(revision 17521)
+++ wp-includes/pluggable.php	(working copy)
@@ -805,13 +805,11 @@
 	// The cookie is no good so force login
 	nocache_headers();
 
-	if ( is_ssl() )
-		$proto = 'https://';
+	if ( strpos( $_SERVER['REQUEST_URI'], '/options.php' ) && $referer = wp_get_referer() )
+		$redirect = $referer;
 	else
-		$proto = 'http://';
+		$redirect = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
 
-	$redirect = ( strpos($_SERVER['REQUEST_URI'], '/options.php') && wp_get_referer() ) ? wp_get_referer() : $proto . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
-
 	$login_url = wp_login_url($redirect, true);
 
 	wp_redirect($login_url);
