Index: wp-admin/includes/ajax-actions.php
===================================================================
--- wp-admin/includes/ajax-actions.php	(revision 22966)
+++ wp-admin/includes/ajax-actions.php	(working copy)
@@ -1950,15 +1950,21 @@
 	if ( 'attachment' != $post->post_type )
 		wp_send_json_error();
 
+	$rel = $url = '';
+	if ( ! empty( $attachment['url'] ) )
+		$url = $attachment['url'];
+	
 	// If this attachment is unattached, attach it. Primarily a back compat thing.
 	if ( 0 == $post->post_parent && $insert_into_post_id = intval( $_POST['post_id'] ) ) {
 		wp_update_post( array( 'ID' => $id, 'post_parent' => $insert_into_post_id ) );
+		
+		// Update attachment url if it contains a default query string, since it may have been 'prettified'.
+		if ( strpos( $url, 'attachment_id') )
+			$url = get_attachment_link( $id );
 	}
 
-	$rel = $url = '';
 	$html = $title = isset( $attachment['post_title'] ) ? $attachment['post_title'] : '';
-	if ( ! empty( $attachment['url'] ) ) {
-		$url = $attachment['url'];
+	if ( ! empty( $url ) ) {
 		if ( strpos( $url, 'attachment_id') || get_attachment_link( $id ) == $url )
 			$rel = ' rel="attachment wp-att-' . $id . '"';
 		$html = '<a href="' . esc_url( $url ) . '"' . $rel . '>' . $html . '</a>';
