Index: wp-includes/template-functions-general.php
===================================================================
--- wp-includes/template-functions-general.php	(revision 2681)
+++ wp-includes/template-functions-general.php	(working copy)
@@ -301,12 +301,12 @@
         if ($arcresults) {
             $afterafter = $after;
             foreach ($arcresults as $arcresult) {
-                $url  = get_month_link($arcresult->year,   $arcresult->month);
+                $url = get_month_link($arcresult->year, $arcresult->month);
                 if ($show_post_count) {
                     $text = sprintf('%s %d', $month[zeroise($arcresult->month,2)], $arcresult->year);
-                    $after = '&nbsp;('.$arcresult->posts.')' . $afterafter;
+                    $after = '&nbsp;(' . $arcresult->posts . ')' . $afterafter;
                 } else {
-                    $text = sprintf('%s %d', $month[zeroise($arcresult->month,2)], $arcresult->year);
+                    $text = sprintf('%s %d', $month[zeroise($arcresult->month, 2)], $arcresult->year);
                 }
                 echo get_archives_link($url, $text, $format, $before, $after);
             }
Index: wp-includes/template-functions-category.php
===================================================================
--- wp-includes/template-functions-category.php	(revision 2681)
+++ wp-includes/template-functions-category.php	(working copy)
@@ -21,7 +21,7 @@
 
 function get_category_link($category_id) {
 	global $wp_rewrite;
-	$catlink = $wp_rewrite->get_category_permastruct();
+	$catlink = user_trailing_slash($wp_rewrite->get_category_permastruct());
 
 	if ( empty($catlink) ) {
 		$file = get_settings('home') . '/' . get_settings('blogfilename');
@@ -34,7 +34,7 @@
 			$category_nicename = get_category_parents($parent, false, '/', true) . $category_nicename . '/';
 
 		$catlink = str_replace('%category%', $category_nicename, $catlink);
-		$catlink = get_settings('home') . trailingslashit($catlink);
+		$catlink = get_settings('home') . $catlink;
 	}
 	return apply_filters('category_link', $catlink, $category_id);
 }
Index: wp-includes/classes.php
===================================================================
--- wp-includes/classes.php	(revision 2681)
+++ wp-includes/classes.php	(working copy)
@@ -813,9 +813,9 @@
 	}					
 
 	function using_index_permalinks() {
-    if (empty($this->permalink_structure)) {
+		if (empty($this->permalink_structure)) {
 			return false;
-    }
+	}
 
     // If the index is not in the permalink, we're using mod_rewrite.
     if (preg_match('#^/*' . $this->index . '#', $this->permalink_structure)) {
@@ -833,15 +833,15 @@
 	}					
 
 	function preg_index($number) {
-    $match_prefix = '$';
-    $match_suffix = '';
+		$match_prefix = '$';
+		$match_suffix = '';
     
-    if (! empty($this->matches)) {
+		if (! empty($this->matches)) {
 			$match_prefix = '$' . $this->matches . '['; 
 			$match_suffix = ']';
-    }        
+		}
     
-    return "$match_prefix$number$match_suffix";        
+		return "$match_prefix$number$match_suffix";
 	}
 
 	function page_rewrite_rules() {
@@ -849,8 +849,7 @@
 
 		$rewrite_rules = array();
 		$page_structure = $this->get_page_permastruct();
-		if( is_array( $uris ) )
-			{
+		if( is_array( $uris ) ) {
 				foreach ($uris as $uri => $pagename) {
 					$this->add_rewrite_tag('%pagename%', "($uri)", 'pagename=');
 					$rewrite_rules += $this->generate_rewrite_rules($page_structure);
@@ -910,8 +909,8 @@
 			return false;
 		}
 
-		$structure = str_replace('%monthnum%', '', $structure);
-		$structure = str_replace('%day%', '', $structure);
+		$structure = str_replace('/%monthnum%', '', $structure);
+		$structure = str_replace('/%day%', '', $structure);
 
 		$structure = preg_replace('#/+#', '/', $structure);
 
@@ -925,7 +924,7 @@
 			return false;
 		}
 
-		$structure = str_replace('%day%', '', $structure);
+		$structure = str_replace('/%day%', '', $structure);
 
 		$structure = preg_replace('#/+#', '/', $structure);
 
@@ -941,7 +940,7 @@
 			return $this->category_structure;
 		}
 
-    if (empty($this->permalink_structure)) {
+		if (empty($this->permalink_structure)) {
 			$this->category_structure = '';
 			return false;
 		}
Index: wp-includes/template-functions-links.php
===================================================================
--- wp-includes/template-functions-links.php	(revision 2681)
+++ wp-includes/template-functions-links.php	(working copy)
@@ -89,9 +89,9 @@
 	if ('' != $pagestruct) {
 		$link = get_page_uri($id);
 		$link = str_replace('%pagename%', $link, $pagestruct);
-		$link = get_settings('home') . "/$link/";
+		$link = user_trailing_slash(get_settings('home') . '/' . $link);
 	} else {
-		$link = get_settings('home') . "/?page_id=$id";
+		$link = get_settings('home') . '/?page_id=' . $id;
 	}
 
 	return apply_filters('page_link', $link, $id);
@@ -103,7 +103,7 @@
 		$yearlink = $wp_rewrite->get_year_permastruct();
     if (!empty($yearlink)) {
         $yearlink = str_replace('%year%', $year, $yearlink);
-        return apply_filters('year_link', get_settings('home') . trailingslashit($yearlink), $year);
+        return apply_filters('year_link', get_settings('home') . $yearlink, $year);
     } else {
         return apply_filters('year_link', get_settings('home') . '/?m=' . $year, $year);
     }
@@ -111,13 +111,13 @@
 
 function get_month_link($year, $month) {
     global $wp_rewrite;
-    if (!$year) $year = gmdate('Y', time()+(get_settings('gmt_offset') * 3600));
-    if (!$month) $month = gmdate('m', time()+(get_settings('gmt_offset') * 3600));
+    if (!$year) $year = gmdate('Y', time() + (get_settings('gmt_offset') * 3600));
+    if (!$month) $month = gmdate('m', time() + (get_settings('gmt_offset') * 3600));
 		$monthlink = $wp_rewrite->get_month_permastruct();
     if (!empty($monthlink)) {
         $monthlink = str_replace('%year%', $year, $monthlink);
         $monthlink = str_replace('%monthnum%', zeroise(intval($month), 2), $monthlink);
-        return apply_filters('month_link', get_settings('home') . trailingslashit($monthlink), $year, $month);
+        return apply_filters('month_link', get_settings('home') . $monthlink, $year, $month);
     } else {
         return apply_filters('month_link', get_settings('home') . '/?m=' . $year . zeroise($month, 2), $year, $month);
     }
@@ -134,7 +134,7 @@
         $daylink = str_replace('%year%', $year, $daylink);
         $daylink = str_replace('%monthnum%', zeroise(intval($month), 2), $daylink);
         $daylink = str_replace('%day%', zeroise(intval($day), 2), $daylink);
-        return apply_filters('day_link', get_settings('home') . trailingslashit($daylink), $year, $month, $day);
+        return apply_filters('day_link', get_settings('home') . $daylink, $year, $month, $day);
     } else {
         return apply_filters('day_link', get_settings('home') . '/?m=' . $year . zeroise($month, 2) . zeroise($day, 2), $year, $month, $day);
     }
@@ -157,7 +157,7 @@
 			$feed = '';
 
 		$permalink = str_replace('%feed%', $feed, $permalink);
-		$permalink = preg_replace('#/+#', '/', "/$permalink/");
+		$permalink = preg_replace('#/+#', '/', "/$permalink");
 		$output =  get_settings('home') . $permalink;
 	} else {
 		if ( false !== strpos($feed, 'comments_') )
Index: wp-includes/template-functions-post.php
===================================================================
--- wp-includes/template-functions-post.php	(revision 2681)
+++ wp-includes/template-functions-post.php	(working copy)
@@ -289,10 +289,10 @@
 	}
 
 	$pages = $wpdb->get_results("SELECT * " .
-															"FROM $wpdb->posts " .
-															"WHERE post_status = 'static' " .
-															"$exclusions " .
-															"ORDER BY " . $r['sort_column'] . " " . $r['sort_order']);
+							"FROM $wpdb->posts " .
+							"WHERE post_status = 'static' " .
+							"$exclusions " .
+							"ORDER BY " . $r['sort_column'] . " " . $r['sort_order']);
 
 	if ( empty($pages) )
 		return array();
@@ -373,7 +373,7 @@
 
 	if($depth)
 		$indent = str_repeat("\t", $depth);
-	//$indent = join('', array_fill(0,$depth,"\t"));
+	//$indent = join('', array_fill(0, $depth, "\t"));
 
 	foreach($page_tree[$parent]['children'] as $page_id) {
 		$cur_page = $page_tree[$page_id];
Index: wp-includes/comment-functions.php
===================================================================
--- wp-includes/comment-functions.php	(revision 2681)
+++ wp-includes/comment-functions.php	(working copy)
@@ -307,7 +307,7 @@
 	$tb_url = get_settings('siteurl') . '/wp-trackback.php?p=' . $id;
 
 	if ( '' != get_settings('permalink_structure') )
-		$tb_url = trailingslashit(get_permalink()) . 'trackback/';
+		$tb_url = user_trailing_slash(trailingslashit(get_permalink()) . 'trackback');
 
 	return $tb_url;
 }
Index: wp-includes/feed-functions.php
===================================================================
--- wp-includes/feed-functions.php	(revision 2681)
+++ wp-includes/feed-functions.php	(working copy)
@@ -82,7 +82,7 @@
 	global $id;
 
 	if ('' != get_settings('permalink_structure'))
-		$url = trailingslashit( get_permalink() ) . 'feed/';
+		$url = user_trailing_slash(trailingslashit(get_permalink()) . 'feed');
 	else
 		$url = get_settings('home') . "/$commentsrssfilename?feed=rss2&amp;p=$id";
 
@@ -97,7 +97,7 @@
 				 $link = get_settings('home') . '?feed=rss2&amp;author=' . $author_id;
        } else {
 				 $link = get_author_link(0, $author_id, $author_nicename);
-				 $link = $link . "feed/";
+				 $link = user_trailing_slash($link . 'feed');
        }
 			 
 			 $link = apply_filters('author_feed_link', $link);
@@ -113,7 +113,7 @@
 				 $link = get_settings('home') . '?feed=rss2&amp;cat=' . $cat_ID;
        } else {
 				 $link = get_category_link($cat_ID);
-				 $link = $link . "feed/";
+				 $link = user_trailing_slash($link . 'feed');
        }
 
 			 $link = apply_filters('category_feed_link', $link);
Index: wp-includes/functions-formatting.php
===================================================================
--- wp-includes/functions-formatting.php	(revision 2681)
+++ wp-includes/functions-formatting.php	(working copy)
@@ -515,13 +515,20 @@
 	return $string;
 }
 
-function trailingslashit($string) {
-    if ( '/' != substr($string, -1)) {
-        $string .= '/';
-    }
-    return $string;
+function trailingslashit($iri) {
+	if ('/' != substr($iri, -1)) {
+		$iri .= '/';
+	}
+	return $iri;
 }
 
+function user_trailing_slash($iri) {
+	if (('/' == substr(get_settings('permalink_structure'), -1)) && ('/' != substr($iri, -1))) {
+		$iri .= '/';
+	}
+	return $iri;
+}
+
 function addslashes_gpc($gpc) {
 	if (!get_magic_quotes_gpc()) {
 		$gpc = addslashes($gpc);