diff --git a/libsoup/soup-auth-manager.c b/libsoup/soup-auth-manager.c
index 5d1d1bc..5ef1021 100644
--- a/libsoup/soup-auth-manager.c
+++ b/libsoup/soup-auth-manager.c
@@ -359,9 +359,9 @@ authenticate_auth (SoupAuthManager *manager, SoupAuth *auth,
 		   gboolean proxy, gboolean can_interact)
 {
 	SoupAuthManagerPrivate *priv = SOUP_AUTH_MANAGER_GET_PRIVATE (manager);
-	SoupURI *uri;
+	SoupURI *uri = soup_message_get_uri (msg);
 
-	if (soup_auth_is_authenticated (auth))
+	if (soup_auth_is_authenticated (auth) && !uri->user && !uri->password)
 		return TRUE;
 
 	if (proxy) {
@@ -378,8 +378,7 @@ authenticate_auth (SoupAuthManager *manager, SoupAuth *auth,
 
 		if (!uri)
 			return FALSE;
-	} else
-		uri = soup_message_get_uri (msg);
+	}
 
 	if (uri->password && !prior_auth_failed) {
 		soup_auth_authenticate (auth, uri->user, uri->password);
diff --git a/tests/auth-test.c b/tests/auth-test.c
index cd72d49..f5cbc12 100644
--- a/tests/auth-test.c
+++ b/tests/auth-test.c
@@ -32,6 +32,10 @@ typedef struct {
 	 */
 	const char *provided;
 
+	/* Whether to pass user and password in the URL or not.
+	 */
+	gboolean url_auth;
+
 	/* Expected passwords, 1 character each. (As with the provided
 	 * passwords, with the addition that '0' means "no
 	 * Authorization header expected".) Used to verify that soup
@@ -43,116 +47,117 @@ typedef struct {
 	guint final_status;
 } SoupAuthTest;
 
-static SoupAuthTest tests[] = {
+static SoupAuthTest *tests;
+
+static SoupAuthTest main_tests[] = {
 	{ "No auth available, should fail",
-	  "Basic/realm1/", "", "0", SOUP_STATUS_UNAUTHORIZED },
+	  "Basic/realm1/", "", FALSE, "0", SOUP_STATUS_UNAUTHORIZED },
 
 	{ "Should fail with no auth, fail again with bad password, and give up",
-	  "Basic/realm2/", "4", "04", SOUP_STATUS_UNAUTHORIZED },
+	  "Basic/realm2/", "4", FALSE, "04", SOUP_STATUS_UNAUTHORIZED },
 
 	{ "Auth provided this time, so should succeed",
-	  "Basic/realm1/", "1", "01", SOUP_STATUS_OK },
+	  "Basic/realm1/", "1", FALSE, "01", SOUP_STATUS_OK },
 
 	{ "Now should automatically reuse previous auth",
-	  "Basic/realm1/", "", "1", SOUP_STATUS_OK },
+	  "Basic/realm1/", "", FALSE, "1", SOUP_STATUS_OK },
 
 	{ "Subdir should also automatically reuse auth",
-	  "Basic/realm1/subdir/", "", "1", SOUP_STATUS_OK },
+	  "Basic/realm1/subdir/", "", FALSE, "1", SOUP_STATUS_OK },
 
 	{ "Subdir should retry last auth, but will fail this time",
-	  "Basic/realm1/realm2/", "", "1", SOUP_STATUS_UNAUTHORIZED },
+	  "Basic/realm1/realm2/", "", FALSE, "1", SOUP_STATUS_UNAUTHORIZED },
 
 	{ "Now should use provided auth",
-	  "Basic/realm1/realm2/", "2", "02", SOUP_STATUS_OK },
+	  "Basic/realm1/realm2/", "2", FALSE, "02", SOUP_STATUS_OK },
 
 	{ "Reusing last auth. Should succeed on first try",
-	  "Basic/realm1/realm2/", "", "2", SOUP_STATUS_OK },
+	  "Basic/realm1/realm2/", "", FALSE, "2", SOUP_STATUS_OK },
 
 	{ "Reuse will fail, but 2nd try will succeed because it's a known realm",
-	  "Basic/realm1/realm2/realm1/", "", "21", SOUP_STATUS_OK },
+	  "Basic/realm1/realm2/realm1/", "", FALSE, "21", SOUP_STATUS_OK },
 
 	{ "Should succeed on first try. (Known realm with cached password)",
-	  "Basic/realm2/", "", "2", SOUP_STATUS_OK },
+	  "Basic/realm2/", "", FALSE, "2", SOUP_STATUS_OK },
 
 	{ "Fail once, then use typoed password, then use right password",
-	  "Basic/realm3/", "43", "043", SOUP_STATUS_OK },
+	  "Basic/realm3/", "43", FALSE, "043", SOUP_STATUS_OK },
 
 
 	{ "No auth available, should fail",
-	  "Digest/realm1/", "", "0", SOUP_STATUS_UNAUTHORIZED },
+	  "Digest/realm1/", "", FALSE, "0", SOUP_STATUS_UNAUTHORIZED },
 
 	{ "Should fail with no auth, fail again with bad password, and give up",
-	  "Digest/realm2/", "4", "04", SOUP_STATUS_UNAUTHORIZED },
+	  "Digest/realm2/", "4", FALSE, "04", SOUP_STATUS_UNAUTHORIZED },
 
 	{ "Known realm, auth provided, so should succeed",
-	  "Digest/realm1/", "1", "01", SOUP_STATUS_OK },
+	  "Digest/realm1/", "1", FALSE, "01", SOUP_STATUS_OK },
 
 	{ "Now should automatically reuse previous auth",
-	  "Digest/realm1/", "", "1", SOUP_STATUS_OK },
+	  "Digest/realm1/", "", FALSE, "1", SOUP_STATUS_OK },
 
 	{ "Subdir should also automatically reuse auth",
-	  "Digest/realm1/subdir/", "", "1", SOUP_STATUS_OK },
+	  "Digest/realm1/subdir/", "", FALSE, "1", SOUP_STATUS_OK },
 
 	{ "Password provided, should succeed",
-	  "Digest/realm2/", "2", "02", SOUP_STATUS_OK },
+	  "Digest/realm2/", "2", FALSE, "02", SOUP_STATUS_OK },
 
 	{ "Should already know correct domain and use provided auth on first try",
-	  "Digest/realm1/realm2/", "2", "2", SOUP_STATUS_OK },
+	  "Digest/realm1/realm2/", "2", FALSE, "2", SOUP_STATUS_OK },
 
 	{ "Reusing last auth. Should succeed on first try",
-	  "Digest/realm1/realm2/", "", "2", SOUP_STATUS_OK },
+	  "Digest/realm1/realm2/", "", FALSE, "2", SOUP_STATUS_OK },
 
 	{ "Should succeed on first try because of earlier domain directive",
-	  "Digest/realm1/realm2/realm1/", "", "1", SOUP_STATUS_OK },
+	  "Digest/realm1/realm2/realm1/", "", FALSE, "1", SOUP_STATUS_OK },
 
 	{ "Fail once, then use typoed password, then use right password",
-	  "Digest/realm3/", "43", "043", SOUP_STATUS_OK },
+	  "Digest/realm3/", "43", FALSE, "043", SOUP_STATUS_OK },
 
 
 	{ "Make sure we haven't forgotten anything",
-	  "Basic/realm1/", "", "1", SOUP_STATUS_OK },
+	  "Basic/realm1/", "", FALSE, "1", SOUP_STATUS_OK },
 
 	{ "Make sure we haven't forgotten anything",
-	  "Basic/realm1/realm2/", "", "2", SOUP_STATUS_OK },
+	  "Basic/realm1/realm2/", "", FALSE, "2", SOUP_STATUS_OK },
 
 	{ "Make sure we haven't forgotten anything",
-	  "Basic/realm1/realm2/realm1/", "", "1", SOUP_STATUS_OK },
+	  "Basic/realm1/realm2/realm1/", "", FALSE, "1", SOUP_STATUS_OK },
 
 	{ "Make sure we haven't forgotten anything",
-	  "Basic/realm2/", "", "2", SOUP_STATUS_OK },
+	  "Basic/realm2/", "", FALSE, "2", SOUP_STATUS_OK },
 
 	{ "Make sure we haven't forgotten anything",
-	  "Basic/realm3/", "", "3", SOUP_STATUS_OK },
+	  "Basic/realm3/", "", FALSE, "3", SOUP_STATUS_OK },
 
 
 	{ "Make sure we haven't forgotten anything",
-	  "Digest/realm1/", "", "1", SOUP_STATUS_OK },
+	  "Digest/realm1/", "", FALSE, "1", SOUP_STATUS_OK },
 
 	{ "Make sure we haven't forgotten anything",
-	  "Digest/realm1/realm2/", "", "2", SOUP_STATUS_OK },
+	  "Digest/realm1/realm2/", "", FALSE, "2", SOUP_STATUS_OK },
 
 	{ "Make sure we haven't forgotten anything",
-	  "Digest/realm1/realm2/realm1/", "", "1", SOUP_STATUS_OK },
+	  "Digest/realm1/realm2/realm1/", "", FALSE, "1", SOUP_STATUS_OK },
 
 	{ "Make sure we haven't forgotten anything",
-	  "Digest/realm2/", "", "2", SOUP_STATUS_OK },
+	  "Digest/realm2/", "", FALSE, "2", SOUP_STATUS_OK },
 
 	{ "Make sure we haven't forgotten anything",
-	  "Digest/realm3/", "", "3", SOUP_STATUS_OK },
+	  "Digest/realm3/", "", FALSE, "3", SOUP_STATUS_OK },
 
 	{ "Now the server will reject the formerly-good password",
-	  "Basic/realm1/not/", "1" /* should not be used */, "1", SOUP_STATUS_UNAUTHORIZED },
+	  "Basic/realm1/not/", "1", FALSE, /* should not be used */ "1", SOUP_STATUS_UNAUTHORIZED },
 
 	{ "Make sure we've forgotten it",
-	  "Basic/realm1/", "", "0", SOUP_STATUS_UNAUTHORIZED },
+	  "Basic/realm1/", "", FALSE, "0", SOUP_STATUS_UNAUTHORIZED },
 
 	{ "Likewise, reject the formerly-good Digest password",
-	  "Digest/realm1/not/", "1" /* should not be used */, "1", SOUP_STATUS_UNAUTHORIZED },
+	  "Digest/realm1/not/", "1", FALSE, /* should not be used */ "1", SOUP_STATUS_UNAUTHORIZED },
 
 	{ "Make sure we've forgotten it",
-	  "Digest/realm1/", "", "0", SOUP_STATUS_UNAUTHORIZED }
+	  "Digest/realm1/", "", FALSE, "0", SOUP_STATUS_UNAUTHORIZED }
 };
-static int ntests = sizeof (tests) / sizeof (tests[0]);
 
 static const char *auths[] = {
 	"no password", "password 1",
@@ -825,31 +830,47 @@ do_select_auth_test (void)
 	soup_test_server_quit_unref (server);
 }
 
-int
-main (int argc, char **argv)
+static SoupAuthTest relogin_tests[] = {
+	{ "Auth provided via URL, should succeed",
+	  "Basic/realm12/", "1", TRUE, "01", SOUP_STATUS_OK },
+
+	{ "Now should automatically reuse previous auth",
+	  "Basic/realm12/", "", FALSE, "1", SOUP_STATUS_OK },
+
+	{ "Different auth provided via URL for the same realm, should succeed",
+	  "Basic/realm12/", "2", TRUE, "2", SOUP_STATUS_OK },
+
+	{ "Subdir should also automatically reuse auth",
+	  "Basic/realm12/subdir/", "", FALSE, "2", SOUP_STATUS_OK },
+
+	{ "Should fail with no auth",
+	  "Basic/realm12/", "4", TRUE, "4", SOUP_STATUS_UNAUTHORIZED },
+
+	{ "Make sure we've forgotten it",
+	  "Basic/realm12/", "", FALSE, "0", SOUP_STATUS_UNAUTHORIZED },
+
+	{ "Should fail with no auth, fail again with bad password, and give up",
+	  "Basic/realm12/", "3", FALSE, "03", SOUP_STATUS_UNAUTHORIZED },
+};
+
+static void
+do_batch_tests (const gchar *base_uri, gint ntests)
 {
 	SoupSession *session;
 	SoupMessage *msg;
-	const char *base_uri;
 	char *uri, *expected;
-	gboolean authenticated;
 	int i;
 
-	test_init (argc, argv, NULL);
-	apache_init ();
-
-	base_uri = "http://127.0.0.1:47524/";
-
 	session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL);
 	g_signal_connect (session, "authenticate",
 			  G_CALLBACK (authenticate), &i);
 
 	for (i = 0; i < ntests; i++) {
+		SoupURI *soup_uri;
+
 		debug_printf (1, "Test %d: %s\n", i + 1, tests[i].explanation);
 
 		uri = g_strconcat (base_uri, tests[i].url, NULL);
-		debug_printf (1, "  GET %s\n", uri);
-
 		msg = soup_message_new (SOUP_METHOD_GET, uri);
 		g_free (uri);
 		if (!msg) {
@@ -857,6 +878,18 @@ main (int argc, char **argv)
 			exit (1);
 		}
 
+		soup_uri = soup_message_get_uri (msg);
+		if (tests[i].url_auth) {
+			gchar *username = g_strdup_printf ("user%c", tests[i].provided[0]);
+			gchar *password = g_strdup_printf ("realm%c", tests[i].provided[0]);
+			soup_uri_set_user (soup_uri, username);
+			soup_uri_set_password (soup_uri, password);
+			g_free (username);
+			g_free (password);
+		}
+
+		debug_printf (1, "  GET %s\n", soup_uri_to_string (soup_message_get_uri (msg), FALSE));
+
 		expected = g_strdup (tests[i].expected);
 		soup_message_add_status_code_handler (
 			msg, "got_headers", SOUP_STATUS_UNAUTHORIZED,
@@ -888,6 +921,32 @@ main (int argc, char **argv)
 		g_object_unref (msg);
 	}
 	soup_test_session_abort_unref (session);
+}
+
+int
+main (int argc, char **argv)
+{
+	SoupSession *session;
+	SoupMessage *msg;
+	const char *base_uri;
+	char *uri;
+	gboolean authenticated;
+	int i, ntests;
+
+	test_init (argc, argv, NULL);
+	apache_init ();
+
+	base_uri = "http://127.0.0.1:47524/";
+
+	/* Main tests */
+	tests = main_tests;
+	ntests = sizeof (main_tests) / sizeof (main_tests[0]);
+	do_batch_tests (base_uri, ntests);
+
+	/* Re-login tests */
+	tests = relogin_tests;
+	ntests = sizeof (relogin_tests) / sizeof (relogin_tests[0]);
+	do_batch_tests (base_uri, ntests);
 
 	/* And now for some regression tests */
 	loop = g_main_loop_new (NULL, TRUE);
diff --git a/tests/httpd.conf.in b/tests/httpd.conf.in
index 164cc00..34ab73e 100644
--- a/tests/httpd.conf.in
+++ b/tests/httpd.conf.in
@@ -85,6 +85,11 @@ Listen 127.0.0.1:47527
     AuthName realm1
     AuthUserFile @srcdir@/htpasswd
     Require valid-user
+
+    AuthType Basic
+    AuthName realm12
+    AuthUserFile ./htpasswd
+    Require valid-user
   </Proxy>
 
   # Allow CONNECT to local https port with authentication
@@ -167,6 +172,8 @@ Alias /Basic/realm1/realm2 @srcdir@
 Alias /Basic/realm1/subdir @srcdir@
 Alias /Basic/realm1/not @srcdir@
 Alias /Basic/realm1 @srcdir@
+Alias /Basic/realm12/subdir @srcdir@
+Alias /Basic/realm12 @srcdir@
 Alias /Basic/realm2 @srcdir@
 Alias /Basic/realm3 @srcdir@
 Alias /Basic @srcdir@
@@ -185,6 +192,13 @@ Alias /Basic @srcdir@
   Require user user2
 </Location>
 
+<Location /Basic/realm12>
+  AuthType Basic
+  AuthName realm12
+  AuthUserFile ./htpasswd
+  Require user user1 user2
+</Location>
+
 <Location /Basic/realm1/realm2>
   AuthType Basic
   AuthName realm2
