Index: wp-includes/post.php
===================================================================
--- wp-includes/post.php (revision 18596)
+++ wp-includes/post.php (working copy)
@@ -3162,23 +3162,22 @@
 	$foundid = 0;
 	foreach ( $pages as $page ) {
 		if ( $page->post_name == $revparts[0] ) {
-			$count = 0;
-			if ( $page->post_parent != 0 ) {
-				if ( null === ( $parent_page = $pages[ $page->post_parent ] ) )
-					continue;
-
-				while ( $parent_page->ID != 0 ) {
-					$count++;
-					if ( $parent_page->post_name != $revparts[ $count ] )
-						break;
-					$parent_page = $pages[ $parent_page->post_parent ];
-				}
+			if ( 1 == count( $revparts ) ) {
+				$foundid = $page->ID;
+				break;
+			}
 
-				if ( $parent_page->ID == 0 && $count+1 == count($revparts) ) {
-					$foundid = $page->ID;
+			$cur_page = $page;
+			$count = 0;
+			while ( ! empty( $cur_page->post_parent ) && isset( $pages[ $cur_page->post_parent ] ) ) {
+				if ( $cur_page->post_name != $revparts[ $count ] )
 					break;
-				}
-			} else if ( count($revparts) == 1 ) {
+
+				$cur_page = $pages[ $cur_page->post_parent ];
+				$count++;
+			}
+
+			if ( empty( $cur_page->post_parent ) && $count+1 == count($revparts) ) {
 				$foundid = $page->ID;
 				break;
 			}
