diff --git wp-includes/post.php wp-includes/post.php
index c4422bc..f0040a9 100644
--- wp-includes/post.php
+++ wp-includes/post.php
@@ -3133,13 +3133,13 @@ function get_page_by_path($page_path, $output = OBJECT, $post_type = 'page') {
 	foreach ( (array) $page_paths as $pathdir )
 		$full_path .= ( $pathdir != '' ? '/' : '' ) . sanitize_title($pathdir);
 
-	$pages = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_name = %s AND (post_type = %s OR post_type = 'attachment')", $leaf_path, $post_type ));
+	$pages = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_name, post_parent, post_type FROM $wpdb->posts WHERE post_name = %s AND (post_type = %s OR post_type = 'attachment')", $leaf_path, $post_type ));
 
 	if ( empty($pages) )
 		return $null;
 
 	foreach ( $pages as $page ) {
-		$path = '/' . $leaf_path;
+		$path = '/' . ( $page->post_type == 'attachment' ? 'attachment/' : '' ) . $leaf_path;
 		$curpage = $page;
 		while ( $curpage->post_parent != 0 ) {
 			$post_parent = $curpage->post_parent;
