Index: wp-includes/canonical.php
===================================================================
--- wp-includes/canonical.php	(revision 21631)
+++ wp-includes/canonical.php	(working copy)
@@ -374,12 +374,6 @@
 	if ( trailingslashit( $redirect['path'] ) == trailingslashit( $user_home['path'] ) )
 		$redirect['path'] = trailingslashit($redirect['path']);
 
-	// Ignore differences in host capitalization, as this can lead to infinite redirects
-	// Only redirect no-www <=> yes-www
-	if ( strtolower($original['host']) == strtolower($redirect['host']) ||
-		( strtolower($original['host']) != 'www.' . strtolower($redirect['host']) && 'www.' . strtolower($original['host']) != strtolower($redirect['host']) ) )
-		$redirect['host'] = $original['host'];
-
 	$compare_original = array($original['host'], $original['path']);
 
 	if ( !empty( $original['port'] ) )
@@ -396,6 +390,12 @@
 	if ( !empty( $redirect['query'] ) )
 		$compare_redirect[] = $redirect['query'];
 
+	// Ignore differences in host capitalization, as this can lead to infinite redirects
+	// Only redirect no-www <=> yes-www
+	if ( strtolower($original['host']) == strtolower($redirect['host']) ||
+		( strtolower($original['host']) != 'www.' . strtolower($redirect['host']) && 'www.' . strtolower($original['host']) != strtolower($redirect['host']) ) )
+		$redirect['host'] = $original['host'];
+
 	if ( $compare_original !== $compare_redirect ) {
 		$redirect_url = $redirect['scheme'] . '://' . $redirect['host'];
 		if ( !empty($redirect['port']) )
