Index: wp-includes/link-template.php
===================================================================
--- wp-includes/link-template.php	(revision 25447)
+++ wp-includes/link-template.php	(working copy)
@@ -321,8 +321,13 @@
 			$link = str_replace( '%postname%', $name, $link );
 	}
 
-	if ( ! $link )
-		$link = home_url( '/?attachment_id=' . $post->ID );
+	if ( ! $link ) {
+		if($wp_rewrite->using_permalinks()) {
+			$link = home_url( '/attachment/' . $post->ID );
+		} else {
+			$link = home_url( '/?attachment_id=' . $post->ID );
+		}
+	}
 
 	return apply_filters( 'attachment_link', $link, $post->ID );
 }
@@ -1468,7 +1473,7 @@
  *
  * @param int $pagenum Optional. Page ID.
  * @param bool $escape Optional. Whether to escape the URL for display, with esc_url(). Defaults to true.
-* 	Otherwise, prepares the URL with esc_url_raw().
+ * Otherwise, prepares the URL with esc_url_raw().
  * @return string
  */
 function get_pagenum_link($pagenum = 1, $escape = true ) {
Index: wp-includes/rewrite.php
===================================================================
--- wp-includes/rewrite.php	(revision 25447)
+++ wp-includes/rewrite.php	(working copy)
@@ -679,7 +679,8 @@
 		'%post_id%',
 		'%author%',
 		'%pagename%',
-		'%search%'
+		'%search%',
+		'%attachment_id%'
 	);
 
 	/**
@@ -722,7 +723,8 @@
 		'p=',
 		'author_name=',
 		'pagename=',
-		's='
+		's=',
+		'attachment_id='
 	);
 
 	/**
@@ -1551,6 +1553,10 @@
 		$post_rewrite = $this->generate_rewrite_rules( $this->permalink_structure, EP_PERMALINK );
 		$post_rewrite = apply_filters('post_rewrite_rules', $post_rewrite);
 
+		// Attachment
+		$attachment_rewrite = $this->generate_rewrite_rules( "/attachment/%attachment_id%", EP_NONE, false, false, false, false, false );
+		$attachment_rewrite = apply_filters('attachment_rewrite_rules', $attachment_rewrite);
+
 		// Date
 		$date_rewrite = $this->generate_rewrite_rules($this->get_date_permastruct(), EP_DATE);
 		$date_rewrite = apply_filters('date_rewrite_rules', $date_rewrite);
@@ -1596,9 +1602,9 @@
 
 		// Put them together.
 		if ( $this->use_verbose_page_rules )
-			$this->rules = array_merge($this->extra_rules_top, $robots_rewrite, $deprecated_files, $registration_pages, $root_rewrite, $comments_rewrite, $search_rewrite,  $author_rewrite, $date_rewrite, $page_rewrite, $post_rewrite, $this->extra_rules);
+			$this->rules = array_merge($this->extra_rules_top, $robots_rewrite, $deprecated_files, $registration_pages, $root_rewrite, $comments_rewrite, $search_rewrite,  $author_rewrite, $date_rewrite, $attachment_rewrite, $page_rewrite, $post_rewrite, $this->extra_rules);
 		else
-			$this->rules = array_merge($this->extra_rules_top, $robots_rewrite, $deprecated_files, $registration_pages, $root_rewrite, $comments_rewrite, $search_rewrite,  $author_rewrite, $date_rewrite, $post_rewrite, $page_rewrite, $this->extra_rules);
+			$this->rules = array_merge($this->extra_rules_top, $robots_rewrite, $deprecated_files, $registration_pages, $root_rewrite, $comments_rewrite, $search_rewrite,  $author_rewrite, $date_rewrite, $attachment_rewrite, $post_rewrite, $page_rewrite, $this->extra_rules);
 
 		do_action_ref_array('generate_rewrite_rules', array(&$this));
 		$this->rules = apply_filters('rewrite_rules_array', $this->rules);
