Index: wp-login.php
===================================================================
--- wp-login.php	(revision 18546)
+++ wp-login.php	(working copy)
@@ -216,7 +216,7 @@
 	$message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n";
 	$message .= __('If this was a mistake, just ignore this email and nothing will happen.') . "\r\n\r\n";
 	$message .= __('To reset your password, visit the following address:') . "\r\n\r\n";
-	$message .= '<' . network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user_login), 'login') . ">\r\n";
+	$message .= '<' . network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user_login), 'login', 'absolute') . ">\r\n";
 
 	if ( is_multisite() )
 		$blogname = $GLOBALS['current_site']->site_name;
Index: wp-includes/feed-rss2.php
===================================================================
--- wp-includes/feed-rss2.php	(revision 18546)
+++ wp-includes/feed-rss2.php	(working copy)
@@ -50,7 +50,7 @@
 		<content:encoded><![CDATA[<?php the_excerpt_rss() ?>]]></content:encoded>
 	<?php endif; ?>
 <?php endif; ?>
-		<wfw:commentRss><?php echo esc_url( get_post_comments_feed_link(null, 'rss2') ); ?></wfw:commentRss>
+		<wfw:commentRss><?php echo esc_url( get_post_comments_feed_link(null, 'rss2', 'absolute') ); ?></wfw:commentRss>
 		<slash:comments><?php echo get_comments_number(); ?></slash:comments>
 <?php rss_enclosure(); ?>
 	<?php do_action('rss2_item'); ?>
Index: wp-includes/default-constants.php
===================================================================
--- wp-includes/default-constants.php	(revision 18546)
+++ wp-includes/default-constants.php	(working copy)
@@ -80,7 +80,7 @@
  */
 function wp_plugin_directory_constants( ) {
 	if ( !defined('WP_CONTENT_URL') )
-		define( 'WP_CONTENT_URL', get_option('siteurl') . '/wp-content'); // full url - WP_CONTENT_DIR is defined further up
+		define( 'WP_CONTENT_URL', get_site_url(null, '', null, 'root_relative') . '/wp-content'); // full url - WP_CONTENT_DIR is defined further up
 
 	/**
 	 * Allows for the plugins directory to be moved from the default location.
Index: wp-includes/comment-template.php
===================================================================
--- wp-includes/comment-template.php	(revision 18546)
+++ wp-includes/comment-template.php	(working copy)
@@ -467,9 +467,10 @@
  *
  * @param object|string|int $comment Comment to retrieve.
  * @param array $args Optional args.
+ * @param string $type Type of link - either 'absolute' or 'root_relative' (default).
  * @return string The permalink to the given comment.
  */
-function get_comment_link( $comment = null, $args = array() ) {
+function get_comment_link( $comment = null, $args = array(), $type = 'root_relative' ) {
 	global $wp_rewrite, $in_comment_loop;
 
 	$comment = get_comment($comment);
@@ -497,11 +498,11 @@
 			$args['page'] = ( !empty($in_comment_loop) ) ? get_query_var('cpage') : get_page_of_comment( $comment->comment_ID, $args );
 
 		if ( $wp_rewrite->using_permalinks() )
-			$link = user_trailingslashit( trailingslashit( get_permalink( $comment->comment_post_ID ) ) . 'comment-page-' . $args['page'], 'comment' );
+			$link = user_trailingslashit( trailingslashit( get_permalink( $comment->comment_post_ID, false, $type ) ) . 'comment-page-' . $args['page'], 'comment' );
 		else
-			$link = add_query_arg( 'cpage', $args['page'], get_permalink( $comment->comment_post_ID ) );
+			$link = add_query_arg( 'cpage', $args['page'], get_permalink( $comment->comment_post_ID, false, $type ) );
 	} else {
-		$link = get_permalink( $comment->comment_post_ID );
+		$link = get_permalink( $comment->comment_post_ID, false, $type );
 	}
 
 	return apply_filters( 'get_comment_link', $link . '#comment-' . $comment->comment_ID, $comment, $args );
@@ -513,10 +514,11 @@
  * @since 1.5.0
  *
  * @param int $post_id Optional post id
+ * @param string $type Type of link - 'absolute' or 'root_relative' (default)
  * @return string The link to the comments
  */
-function get_comments_link($post_id = 0) {
-	return get_permalink($post_id) . '#comments';
+function get_comments_link($post_id = 0, $type = 'root_relative') {
+	return get_permalink($post_id, false, $type) . '#comments';
 }
 
 /**
Index: wp-includes/link-template.php
===================================================================
--- wp-includes/link-template.php	(revision 18546)
+++ wp-includes/link-template.php	(working copy)
@@ -75,9 +75,10 @@
  *
  * @param int $id Optional. Post ID.
  * @param bool $leavename Optional, defaults to false. Whether to keep post name or page name.
+ * @param string $type Optional. Either 'absolute' or 'root_relative'. Defaults to 'root_relative'.
  * @return string
  */
-function get_permalink($id = 0, $leavename = false) {
+function get_permalink($id = 0, $leavename = false, $type = 'root_relative') {
 	$rewritecode = array(
 		'%year%',
 		'%monthnum%',
@@ -155,10 +156,10 @@
 			$author,
 			$post->post_name,
 		);
-		$permalink = home_url( str_replace($rewritecode, $rewritereplace, $permalink) );
+		$permalink = home_url( str_replace($rewritecode, $rewritereplace, $permalink), null, $type );
 		$permalink = user_trailingslashit($permalink, 'single');
 	} else { // if they're not using the fancy permalink option
-		$permalink = home_url('?p=' . $post->ID);
+		$permalink = home_url('?p=' . $post->ID, null, $type);
 	}
 	return apply_filters('post_link', $permalink, $post, $leavename);
 }
@@ -463,9 +464,10 @@
  *
  * @param int $post_id Optional. Post ID.
  * @param string $feed Optional. Feed type.
+ * @param string $type Optional. Either 'absolute' or 'root_relative'. Defaults to root_relative.
  * @return string
  */
-function get_post_comments_feed_link($post_id = 0, $feed = '') {
+function get_post_comments_feed_link($post_id = 0, $feed = '', $type = 'root_relative') {
 	$post_id = absint( $post_id );
 
 	if ( ! $post_id )
@@ -485,11 +487,11 @@
 			$url .= "/$feed";
 		$url = user_trailingslashit($url, 'single_feed');
 	} else {
-		$type = get_post_field('post_type', $post_id);
-		if ( 'page' == $type )
-			$url = home_url("?feed=$feed&amp;page_id=$post_id");
+		$post_type = get_post_field('post_type', $post_id);
+		if ( 'page' == $post_type )
+			$url = home_url("?feed=$feed&amp;page_id=$post_id", null, $type);
 		else
-			$url = home_url("?feed=$feed&amp;p=$post_id");
+			$url = home_url("?feed=$feed&amp;p=$post_id", null, $type);
 	}
 
 	return apply_filters('post_comments_feed_link', $url);
@@ -1944,12 +1946,13 @@
  *
  * @uses get_home_url()
  *
- * @param  string $path   (optional) Path relative to the home url.
- * @param  string $scheme (optional) Scheme to give the home url context. Currently 'http','https'
+ * @param string $path   (optional) Path relative to the home url.
+ * @param string $scheme (optional) Scheme to give the home url context. Currently 'http','https'
+ * @param string $type Optional. Type of link - either 'absolute' or 'root_relative'. Defaults to root_relative.
  * @return string Home url link with optional path appended.
 */
-function home_url( $path = '', $scheme = null ) {
-	return get_home_url(null, $path, $scheme);
+function home_url( $path = '', $scheme = null, $type = 'root_relative' ) {
+	return get_home_url(null, $path, $scheme, $type);
 }
 
 /**
@@ -1967,7 +1970,7 @@
  * @param  string $scheme (optional) Scheme to give the home url context. Currently 'http','https'
  * @return string Home url link with optional path appended.
 */
-function get_home_url( $blog_id = null, $path = '', $scheme = null ) {
+function get_home_url( $blog_id = null, $path = '', $scheme = null, $type = 'root_relative' ) {
 	$orig_scheme = $scheme;
 
 	if ( !in_array( $scheme, array( 'http', 'https' ) ) )
@@ -1980,6 +1983,11 @@
 
 	if ( 'http' != $scheme )
 		$url = str_replace( 'http://', "$scheme://", $url );
+		
+	if ( $type == 'root_relative' ) {
+		$url_parts = parse_url($url);
+		$url = $url_parts['path'] . (array_key_exists('query',$url_parts) ? '?'.$url_parts['query'] : '');
+	}
 
 	if ( !empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false )
 		$url .= '/' . ltrim( $path, '/' );
@@ -2001,10 +2009,11 @@
  *
  * @param string $path Optional. Path relative to the site url.
  * @param string $scheme Optional. Scheme to give the site url context. Currently 'http','https', 'login', 'login_post', or 'admin'.
+ * @param string $type Optional. Type of link - either 'absolute' or 'root_relative'. Defaults to root_relative.
  * @return string Site url link with optional path appended.
 */
-function site_url( $path = '', $scheme = null ) {
-	return get_site_url(null, $path, $scheme);
+function site_url( $path = '', $scheme = null, $type = 'root_relative' ) {
+	return get_site_url(null, $path, $scheme, $type);
 }
 
 /**
@@ -2020,9 +2029,10 @@
  * @param int $blog_id (optional) Blog ID. Defaults to current blog.
  * @param string $path Optional. Path relative to the site url.
  * @param string $scheme Optional. Scheme to give the site url context. Currently 'http','https', 'login', 'login_post', or 'admin'.
+ * @param string $type Optional. Type of link - either 'absolute' or 'root_relative'. Defaults to root_relative.
  * @return string Site url link with optional path appended.
 */
-function get_site_url( $blog_id = null, $path = '', $scheme = null ) {
+function get_site_url( $blog_id = null, $path = '', $scheme = null, $type = 'root_relative' ) {
 	// should the list of allowed schemes be maintained elsewhere?
 	$orig_scheme = $scheme;
 	if ( !in_array( $scheme, array( 'http', 'https' ) ) ) {
@@ -2044,6 +2054,11 @@
 	if ( 'http' != $scheme )
 		$url = str_replace( 'http://', "{$scheme}://", $url );
 
+	if ( $type == 'root_relative' ) {
+		$url_parts = parse_url($url);
+		$url = $url_parts['path'] . (array_key_exists('query',$url_parts) ? '?'.$url_parts['query'] : '');
+	}
+
 	if ( !empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false )
 		$url .= '/' . ltrim( $path, '/' );
 
@@ -2118,7 +2133,7 @@
 
 	if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
 		$url .= '/' . ltrim($path, '/');
-
+	
 	return apply_filters('content_url', $url, $path);
 }
 
@@ -2173,13 +2188,14 @@
  *
  * @param string $path Optional. Path relative to the site url.
  * @param string $scheme Optional. Scheme to give the site url context. Currently 'http','https', 'login', 'login_post', or 'admin'.
+ * @param string $type Optional. Either 'absolute' or 'root_relative'. Defaults to 'root_relative'.
  * @return string Site url link with optional path appended.
 */
-function network_site_url( $path = '', $scheme = null ) {
+function network_site_url( $path = '', $scheme = null, $type = 'root_relative' ) {
 	global $current_site;
 
 	if ( !is_multisite() )
-		return site_url($path, $scheme);
+		return site_url($path, $scheme, $type);
 
 	$orig_scheme = $scheme;
 	if ( !in_array($scheme, array('http', 'https')) ) {
@@ -2198,6 +2214,11 @@
 	if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
 		$url .= ltrim($path, '/');
 
+	if ( $type == 'root_relative' ) {
+		$url_parts = parse_url($url);
+		$url = $url_parts['path'] . (array_key_exists('query',$url_parts) ? '?'.$url_parts['query'] : '');
+	}
+
 	return apply_filters('network_site_url', $url, $path, $orig_scheme);
 }
 
@@ -2213,13 +2234,14 @@
  *
  * @param  string $path   (optional) Path relative to the home url.
  * @param  string $scheme (optional) Scheme to give the home url context. Currently 'http','https'
+ * @param  string $type   (optional) Type of URL. Either 'absolute' or (default)'root_relative'
  * @return string Home url link with optional path appended.
 */
-function network_home_url( $path = '', $scheme = null ) {
+function network_home_url( $path = '', $scheme = null, $type = 'root_relative' ) {
 	global $current_site;
 
 	if ( !is_multisite() )
-		return home_url($path, $scheme);
+		return home_url($path, $scheme, $type);
 
 	$orig_scheme = $scheme;
 
@@ -2231,6 +2253,11 @@
 	if ( !empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false )
 		$url .= ltrim( $path, '/' );
 
+	if ( $type == 'root_relative' ) {
+		$url_parts = parse_url($url);
+		$url = $url_parts['path'] . (array_key_exists('query',$url_parts) ? '?'.$url_parts['query'] : '');
+	}
+
 	return apply_filters( 'network_home_url', $url, $path, $orig_scheme);
 }
 
Index: wp-includes/feed-rss2-comments.php
===================================================================
--- wp-includes/feed-rss2-comments.php	(revision 18546)
+++ wp-includes/feed-rss2-comments.php	(working copy)
@@ -26,7 +26,7 @@
 			printf(ent2ncr(__('Comments for %s')), get_bloginfo_rss( 'name' ) . get_wp_title_rss());
 	?></title>
 	<atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
-	<link><?php (is_single()) ? the_permalink_rss() : bloginfo_rss("url") ?></link>
+	<link><?php if(is_single()) { the_permalink_rss(); } else { echo home_url('',null,'absolute'); } ?></link>
 	<description><?php bloginfo_rss("description") ?></description>
 	<lastBuildDate><?php echo mysql2date('r', get_lastcommentmodified('GMT')); ?></lastBuildDate>
 	<sy:updatePeriod><?php echo apply_filters( 'rss_update_period', 'hourly' ); ?></sy:updatePeriod>
@@ -47,7 +47,7 @@
 				printf(ent2ncr(__('By: %s')), get_comment_author_rss());
 			}
 		?></title>
-		<link><?php comment_link() ?></link>
+		<link><?php comment_link('absolute') ?></link>
 		<dc:creator><?php echo get_comment_author_rss() ?></dc:creator>
 		<pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_comment_time('Y-m-d H:i:s', true, false), false); ?></pubDate>
 		<guid isPermaLink="false"><?php comment_guid() ?></guid>
Index: wp-includes/general-template.php
===================================================================
--- wp-includes/general-template.php	(revision 18546)
+++ wp-includes/general-template.php	(working copy)
@@ -229,10 +229,11 @@
  *
  * @param string $redirect Path to redirect to on login.
  * @param bool $force_reauth Whether to force reauthorization, even if a cookie is present. Default is false.
+ * @param string $type Absolute or relative url - 'absolute' or 'root_relative' (default).
  * @return string A log in url
  */
-function wp_login_url($redirect = '', $force_reauth = false) {
-	$login_url = site_url('wp-login.php', 'login');
+function wp_login_url($redirect = '', $force_reauth = false, $type = 'root_relative') {
+	$login_url = site_url('wp-login.php', 'login', $type);
 
 	if ( !empty($redirect) )
 		$login_url = add_query_arg('redirect_to', urlencode($redirect), $login_url);
Index: wp-includes/canonical.php
===================================================================
--- wp-includes/canonical.php	(revision 18546)
+++ wp-includes/canonical.php	(working copy)
@@ -287,7 +287,7 @@
 		$redirect = @parse_url($redirect_url);
 
 	// www.example.com vs example.com
-	$user_home = @parse_url(home_url());
+	$user_home = @parse_url(home_url('',null,'absolute'));
 	if ( !empty($user_home['host']) )
 		$redirect['host'] = $user_home['host'];
 	if ( empty($user_home['path']) )
Index: wp-includes/pluggable.php
===================================================================
--- wp-includes/pluggable.php	(revision 18546)
+++ wp-includes/pluggable.php	(working copy)
@@ -1240,7 +1240,7 @@
 
 	$message  = sprintf(__('Username: %s'), $user_login) . "\r\n";
 	$message .= sprintf(__('Password: %s'), $plaintext_pass) . "\r\n";
-	$message .= wp_login_url() . "\r\n";
+	$message .= wp_login_url('',false,'absolute') . "\r\n";
 
 	wp_mail($user_email, sprintf(__('[%s] Your username and password'), $blogname), $message);
 
Index: wp-includes/feed.php
===================================================================
--- wp-includes/feed.php	(revision 18546)
+++ wp-includes/feed.php	(working copy)
@@ -187,7 +187,7 @@
  * @uses apply_filters() Call 'the_permalink_rss' on the post permalink
  */
 function the_permalink_rss() {
-	echo esc_url( apply_filters('the_permalink_rss', get_permalink() ));
+	echo esc_url( apply_filters('the_permalink_rss', get_permalink(0,false,'absolute') ));
 }
 
 /**
@@ -197,7 +197,7 @@
  * @return none
  */
 function comments_link_feed() {
-	echo esc_url( get_comments_link() );
+	echo esc_url( get_comments_link(0,'absolute') );
 }
 
 /**
@@ -236,9 +236,10 @@
  * Display the link to the comments.
  *
  * @since 1.5.0
+ * @param $type Optional. Type of link - either 'absolute' or 'root_relative' (default)
  */
-function comment_link() {
-	echo esc_url( get_comment_link() );
+function comment_link($type = 'root_relative') {
+	echo esc_url( get_comment_link(null, Array(), $type) );
 }
 
 /**
@@ -486,12 +487,13 @@
  * @since 2.5
  */
 function self_link() {
-	$host = @parse_url(home_url());
-	$host = $host['host'];
+	$host_array = @parse_url(home_url('',null,'absolute'));
+	$host = $host_array['host'];
 	echo esc_url(
 		'http'
 		. ( (isset($_SERVER['https']) && $_SERVER['https'] == 'on') ? 's' : '' ) . '://'
 		. $host
+		. ( (array_key_exists('port',$host_array)) ? ':'.strval($host_array['port']) : '')
 		. stripslashes($_SERVER['REQUEST_URI'])
 		);
 }
Index: xmlrpc.php
===================================================================
--- xmlrpc.php	(revision 18546)
+++ xmlrpc.php	(working copy)
@@ -38,11 +38,11 @@
     <engineLink>http://wordpress.org/</engineLink>
     <homePageLink><?php bloginfo_rss('url') ?></homePageLink>
     <apis>
-      <api name="WordPress" blogID="1" preferred="true" apiLink="<?php echo site_url('xmlrpc.php', 'rpc') ?>" />
-      <api name="Movable Type" blogID="1" preferred="false" apiLink="<?php echo site_url('xmlrpc.php', 'rpc') ?>" />
-      <api name="MetaWeblog" blogID="1" preferred="false" apiLink="<?php echo site_url('xmlrpc.php', 'rpc') ?>" />
-      <api name="Blogger" blogID="1" preferred="false" apiLink="<?php echo site_url('xmlrpc.php', 'rpc') ?>" />
-      <api name="Atom" blogID="" preferred="false" apiLink="<?php echo site_url('wp-app.php/service', 'rpc') ?>" />
+      <api name="WordPress" blogID="1" preferred="true" apiLink="<?php echo site_url('xmlrpc.php', 'rpc', 'absolute') ?>" />
+      <api name="Movable Type" blogID="1" preferred="false" apiLink="<?php echo site_url('xmlrpc.php', 'rpc', 'absolute') ?>" />
+      <api name="MetaWeblog" blogID="1" preferred="false" apiLink="<?php echo site_url('xmlrpc.php', 'rpc', 'absolute') ?>" />
+      <api name="Blogger" blogID="1" preferred="false" apiLink="<?php echo site_url('xmlrpc.php', 'rpc', 'absolute') ?>" />
+      <api name="Atom" blogID="" preferred="false" apiLink="<?php echo site_url('wp-app.php/service', 'rpc', 'absolute') ?>" />
     </apis>
   </service>
 </rsd>
Index: wp-admin/includes/ms.php
===================================================================
--- wp-admin/includes/ms.php	(revision 18546)
+++ wp-admin/includes/ms.php	(working copy)
@@ -237,7 +237,7 @@
 	$content = str_replace( '###ADMIN_URL###', esc_url( admin_url( 'options.php?adminhash='.$hash ) ), $content );
 	$content = str_replace( '###EMAIL###', $value, $content );
 	$content = str_replace( '###SITENAME###', get_site_option( 'site_name' ), $content );
-	$content = str_replace( '###SITEURL###', network_home_url(), $content );
+	$content = str_replace( '###SITEURL###', network_home_url('',null,'absolute'), $content );
 
 	wp_mail( $value, sprintf( __( '[%s] New Admin Email Address' ), get_option( 'blogname' ) ), $content );
 }
@@ -290,7 +290,7 @@
 		$content = str_replace( '###ADMIN_URL###', esc_url( admin_url( 'profile.php?newuseremail='.$hash ) ), $content );
 		$content = str_replace( '###EMAIL###', $_POST['email'], $content);
 		$content = str_replace( '###SITENAME###', get_site_option( 'site_name' ), $content );
-		$content = str_replace( '###SITEURL###', network_home_url(), $content );
+		$content = str_replace( '###SITEURL###', network_home_url('',null,'absolute'), $content );
 
 		wp_mail( $_POST['email'], sprintf( __( '[%s] New Email Address' ), get_option( 'blogname' ) ), $content );
 		$_POST['email'] = $current_user->user_email;
Index: wp-admin/user-new.php
===================================================================
--- wp-admin/user-new.php	(revision 18546)
+++ wp-admin/user-new.php	(working copy)
@@ -73,7 +73,7 @@
 			$newuser_key = substr( md5( $user_id ), 0, 5 );
 			add_option( 'new_user_' . $newuser_key, array( 'user_id' => $user_id, 'email' => $user_details->user_email, 'role' => $_REQUEST[ 'role' ] ) );
 			$message = __("Hi,\n\nYou have been invited to join '%s' at\n%s with the role of %s.\nPlease click the following link to confirm the invite:\n%s\n");
-			wp_mail( $new_user_email, sprintf( __( '[%s] Joining confirmation' ), get_option( 'blogname' ) ),  sprintf($message, get_option('blogname'), site_url(), $_REQUEST[ 'role' ], site_url("/newbloguser/$newuser_key/")));
+			wp_mail( $new_user_email, sprintf( __( '[%s] Joining confirmation' ), get_option( 'blogname' ) ),  sprintf($message, get_option('blogname'), site_url('',null,'absolute'), $_REQUEST[ 'role' ], site_url("/newbloguser/$newuser_key/",null,'absolute')));
 			$redirect = add_query_arg( array('update' => 'add'), 'user-new.php' );
 		}
 	}