Index: wp-admin/includes/ms.php
===================================================================
--- wp-admin/includes/ms.php	(revision 13880)
+++ wp-admin/includes/ms.php	(working copy)
@@ -713,7 +713,7 @@
 				<?php foreach( (array) $all_blogs as $blog ) {
 					if ( $primary_blog == $blog->userblog_id )
 						$found = true;
-					?><option value='<?php echo $blog->userblog_id ?>'<?php if ( $primary_blog == $blog->userblog_id ) echo ' selected="selected"' ?>>http://<?php echo $blog->domain.$blog->path ?></option><?php
+					?><option value='<?php echo $blog->userblog_id ?>'<?php if ( $primary_blog == $blog->userblog_id ) echo ' selected="selected"' ?>><?php echo $blog->homeurl?></option><?php
 				} ?>
 			</select>
 			<?php
Index: wp-admin/my-sites.php
===================================================================
--- wp-admin/my-sites.php	(revision 13880)
+++ wp-admin/my-sites.php	(working copy)
@@ -68,7 +68,7 @@
 			$t = $t == 'border-right: 1px solid #ccc;' ? '' : 'border-right: 1px solid #ccc;';
 			echo "<td valign='top' style='$t; width:50%'>";
 			echo "<h3>{$user_blog->blogname}</h3>";
-			echo "<p>" . apply_filters( "myblogs_blog_actions", "<a href='{$user_blog->siteurl}'>" . __( 'Visit' ) . "</a> | <a href='{$user_blog->siteurl}/wp-admin/'>" . __( 'Dashboard' ) . "</a>", $user_blog ) . "</p>";
+			echo "<p>" . apply_filters( "myblogs_blog_actions", "<a href='{$user_blog->homeurl}'>" . __( 'Visit' ) . "</a> | <a href='{$user_blog->siteurl}/wp-admin/'>" . __( 'Dashboard' ) . "</a>", $user_blog ) . "</p>";
 			echo apply_filters( 'myblogs_options', '', $user_blog );
 			echo "</td>";
 		}
Index: wp-includes/link-template.php
===================================================================
--- wp-includes/link-template.php	(revision 13880)
+++ wp-includes/link-template.php	(working copy)
@@ -1836,7 +1836,7 @@
 	if ( empty($blog_id) || !is_multisite() )
 		$home = get_option('home');
 	else
-		$home = untrailingslashit(get_blogaddress_by_id($blog_id));
+		$home = get_blog_option($blog_id,'home');
 
 	$url = str_replace( 'http://', "$scheme://", $home );
 
@@ -1898,13 +1898,11 @@
 	if ( empty($blog_id) || !is_multisite() )
 		$url = get_option('siteurl');
 	else
-		$url = untrailingslashit(get_blogaddress_by_id($blog_id));
-
+		$url = get_blog_option($blog_id,'siteurl');
 	$url = str_replace( 'http://', "{$scheme}://", $url );
 
 	if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
 		$url .= '/' . ltrim($path, '/');
-
 	return apply_filters('site_url', $url, $path, $orig_scheme, $blog_id);
 }
 
Index: wp-includes/ms-blogs.php
===================================================================
--- wp-includes/ms-blogs.php	(revision 13880)
+++ wp-includes/ms-blogs.php	(working copy)
@@ -19,8 +19,7 @@
 }
 
 function get_blogaddress_by_id( $blog_id ) {
-	$bloginfo = get_blog_details( (int) $blog_id, false ); // only get bare details!
-	return esc_url( 'http://' . $bloginfo->domain . $bloginfo->path );
+	return get_blog_option($blog_id,'home');
 }
 
 function get_blogaddress_by_name( $blogname ) {
@@ -29,15 +28,15 @@
 	if ( is_subdomain_install() ) {
 		if ( $blogname == 'main' )
 			$blogname = 'www';
-		return esc_url( 'http://' . $blogname . '.' . $current_site->domain . $current_site->path );
+		return esc_url( 'http://' . $blogname . '.' . trailingslashit($current_site->homeurl) );
 	} else {
-		return esc_url( 'http://' . $current_site->domain . $current_site->path . $blogname . '/' );
+		return esc_url( 'http://' . trailingslashit($current_site->homeurl) . $blogname . '/' );
 	}
 }
 
 function get_blogaddress_by_domain( $domain, $path ){
 	if ( is_subdomain_install() ) {
-		$url = "http://".$domain.$path;
+		$url = "http://".$domain;
 	} else {
 		if ( $domain != $_SERVER['HTTP_HOST'] ) {
 			$blogname = substr( $domain, 0, strpos( $domain, '.' ) );
@@ -165,7 +164,7 @@
 		wp_cache_set( $blog_id . $all, $details, 'blog-details' );
 		return $details;
 	}
-
+	$details->homeurl		= get_blog_option( $blog_id, 'home');
 	$details->blogname		= get_blog_option( $blog_id, 'blogname' );
 	$details->siteurl		= get_blog_option( $blog_id, 'siteurl' );
 	$details->post_count	= get_blog_option( $blog_id, 'post_count' );
Index: wp-includes/ms-functions.php
===================================================================
--- wp-includes/ms-functions.php	(revision 13880)
+++ wp-includes/ms-functions.php	(working copy)
@@ -68,6 +68,7 @@
 				$blogs[ $blog_id ]->path			= $blog->path;
 				$blogs[ $blog_id ]->site_id		= $blog->site_id;
 				$blogs[ $blog_id ]->siteurl		= $blog->siteurl;
+				$blogs[ $blog_id ]->homeurl		= $blog->homeurl;				
 			}
 		}
 	}
Index: wp-includes/ms-load.php
===================================================================
--- wp-includes/ms-load.php	(revision 13880)
+++ wp-includes/ms-load.php	(working copy)
@@ -96,11 +96,13 @@
  * @return object $current_site object
  */
 function wpmu_current_site() {
-	global $wpdb, $current_site, $domain, $path, $sites, $cookie_domain;
+	global $wpdb, $current_site, $domain, $path, $sites, $cookie_domain,$sitepath;
+	$sitepath = defined('PATH_WP_INSTALL') ? PATH_WP_INSTALL:'';
 	if ( defined( 'DOMAIN_CURRENT_SITE' ) && defined( 'PATH_CURRENT_SITE' ) ) {
 		$current_site->id = defined( 'SITE_ID_CURRENT_SITE' ) ? SITE_ID_CURRENT_SITE : 1;
 		$current_site->domain = DOMAIN_CURRENT_SITE;
 		$current_site->path   = $path = PATH_CURRENT_SITE;
+		$current_site->sitepath = $sitepath;
 		if ( defined( 'BLOG_ID_CURRENT_SITE' ) )
 			$current_site->blog_id = BLOG_ID_CURRENT_SITE;
 		elseif ( defined( 'BLOGID_CURRENT_SITE' ) ) // deprecated.
@@ -111,7 +113,13 @@
 			$current_site->cookie_domain = substr( $current_site->domain, 4 );
 		else
 			$current_site->cookie_domain = $current_site->domain;
-
+		if(is_subdomain_install()){
+			$current_site->homeurl=$current_site->domain;
+			$current_site->siteurl=$current_site->domain.$current_site->sitepath;
+		}else{
+			$current_site->homeurl=$current_site->domain.$current_site->path;
+			$current_site->siteurl=$current_site->domain.$current_site->path.$current_site->sitepath;			
+		}
 		wp_load_core_site_options( $current_site->id );
 
 		return $current_site;
@@ -120,7 +128,7 @@
 	$current_site = wp_cache_get( 'current_site', 'site-options' );
 	if ( $current_site )
 		return $current_site;
-
+	
 	$sites = $wpdb->get_results( "SELECT * FROM $wpdb->site" ); // usually only one site
 	if ( 1 == count( $sites ) ) {
 		$current_site = $sites[0];
@@ -130,6 +138,14 @@
 		$current_site = get_current_site_name( $current_site );
 		if ( substr( $current_site->domain, 0, 4 ) == 'www.' )
 			$current_site->cookie_domain = substr( $current_site->domain, 4 );
+		$current_site->sitepath = $sitepath;			
+		if(is_subdomain_install()){
+			$current_site->homeurl=$current_site->domain;
+			$current_site->siteurl=$current_site->domain.$current_site->sitepath;
+		}else{
+			$current_site->homeurl=$current_site->domain.$current_site->path;
+			$current_site->siteurl=$current_site->domain.$current_site->path.$current_site->sitepath;			
+		}		
 		wp_cache_set( 'current_site', $current_site, 'site-options' );
 		return $current_site;
 	}
@@ -150,6 +166,14 @@
 	if ( $current_site ) {
 		$path = $current_site->path;
 		$current_site->cookie_domain = $cookie_domain;
+		$current_site->sitepath = $sitepath;	
+		if(is_subdomain_install()){
+			$current_site->homeurl=$current_site->domain;
+			$current_site->siteurl=$current_site->domain.$current_site->sitepath;
+		}else{
+			$current_site->homeurl=$current_site->domain.$current_site->path;
+			$current_site->siteurl=$current_site->domain.$current_site->path.$current_site->sitepath;			
+		}		
 		return $current_site;
 	}
 
@@ -157,15 +181,25 @@
 		$sitedomain = substr( $domain, 1 + strpos( $domain, '.' ) );
 		$current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path = %s", $sitedomain, $path) );
 		if ( $current_site ) {
+			$current_site->sitepath = $sitepath;			
 			$current_site->cookie_domain = $current_site->domain;
+			$current_site->homeurl=$current_site->domain;
+			$current_site->siteurl=$current_site->domain.$current_site->sitepath;	
 			return $current_site;
 		}
-
 		$current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path='/'", $sitedomain) );
 	}
 
 	if ( $current_site || defined( 'WP_INSTALLING' ) ) {
-		$path = '/';
+		$path = '/';	
+		$current_site->sitepath = $sitepath;	
+		if(is_subdomain_install()){
+			$current_site->homeurl=$current_site->domain;
+			$current_site->siteurl=$current_site->domain.$current_site->sitepath;
+		}else{
+			$current_site->homeurl=$current_site->domain.$current_site->path;
+			$current_site->siteurl=$current_site->domain.$current_site->path.$current_site->sitepath;			
+		}	
 		return $current_site;
 	}
 
