Index: wp-includes/canonical.php
===================================================================
--- wp-includes/canonical.php	(revision 6365)
+++ wp-includes/canonical.php	(working copy)
@@ -26,7 +26,7 @@
 
 	// These tests give us a WP-generated permalink
 	if ( is_404() ) {
-		$redirect_url = redirect_guess_404_permalink();
+		$redirect_url = redirect_guess_404_permalink($original);
 	} elseif ( is_object($wp_rewrite) && $wp_rewrite->using_permalinks() ) {
 		// rewriting of old ?p=X, ?m=2004, ?m=200401, ?m=20040101
 		if ( is_single() && isset($_GET['p']) ) {
@@ -157,7 +157,6 @@
 	}
 
 	if ( $redirect_url && $redirect_url != $requested_url ) {
-		// var_dump($redirect_url); die();
 		$redirect_url = apply_filters('redirect_canonical', $redirect_url, $requested_url);
 		if ( $do_redirect) {
 			// protect against chained redirects
@@ -175,13 +174,22 @@
 	}
 }
 
-function redirect_guess_404_permalink() {
+function redirect_guess_404_permalink($original_url) {
 	global $wpdb;
-	if ( !get_query_var('name') )
-		return false;
+	$name = get_query_var('name');
+	$order = '';
 
-	$where = $wpdb->prepare("post_name LIKE %s", get_query_var('name') . '%');
+	if ( empty($name) ){
+		// Check to see if we can pull a postname/page name from the url thats not in the permalink structure
+		//Match string that starts with /, does not contain / and optionally may be followed by / then end of string
+		if( ! preg_match('|\/([^\/.]+)\/?$|', $original_url['path'], $pagemat ) )
+			return false;
+		$name = $pagemat[1];
+		$order = "ORDER BY post_parent ASC, post_name ASC";
+	}
 
+	$where = $wpdb->prepare("post_name LIKE %s", $name . '%');
+
 	// if any of year, monthnum, or day are set, use them to refine the query
 	if ( get_query_var('year') )
 		$where .= $wpdb->prepare(" AND YEAR(post_date) = %d", get_query_var('year'));
@@ -190,7 +198,7 @@
 	if ( get_query_var('day') )
 		$where .= $wpdb->prepare(" AND DAYOFMONTH(post_date) = %d", get_query_var('day'));
 
-	$post_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE $where AND post_status = 'publish'");
+	$post_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE $where AND post_status = 'publish' $order LIMIT 1");
 	if ( !$post_id )
 		return false;
 	return get_permalink($post_id);
