Index: wp-includes/link-template.php
===================================================================
--- wp-includes/link-template.php	(revision 11132)
+++ wp-includes/link-template.php	(working copy)
@@ -1229,8 +1229,17 @@
 	$home_root = parse_url(get_option('home'));
 	$home_root = ( isset($home_root['path']) ) ? $home_root['path'] : '';
 	$home_root = preg_quote( trailingslashit( $home_root ), '|' );
+	if ( get_option('home') != get_option('siteurl') ) {
+		$site_root = parse_url(get_option('siteurl'));
+		$site_root = ( isset($site_root['path']) ) ? $site_root['path'] : '';
+		$site_root = preg_quote( trailingslashit( $site_root ), '|' );
+	} else {
+		$site_root = false;
+	}
 
 	$request = preg_replace('|^'. $home_root . '|', '', $request);
+	if ( $site_root )
+		$request = preg_replace('|^'. $home_root . '|', '', $request);
 	$request = preg_replace('|^/+|', '', $request);
 
 	if ( !$wp_rewrite->using_permalinks() || is_admin() ) {
Index: wp-includes/classes.php
===================================================================
--- wp-includes/classes.php	(revision 11132)
+++ wp-includes/classes.php	(working copy)
@@ -165,6 +165,16 @@
 			else
 				$home_path = '';
 			$home_path = trim($home_path, '/');
+			if ( get_option('home') != get_option('siteurl') ) {
+				$site_path = parse_url(get_option('siteurl'));
+				if ( isset($site_path['path']) )
+					$site_path = $site_path['path'];
+				else
+					$site_path = '';
+				$site_path = trim($site_path, '/');
+			} else {
+				$site_path = false;
+			}
 
 			// Trim path info from the end and the leading home path from the
 			// front.  For path info requests, this leaves us with the requesting
@@ -173,12 +183,18 @@
 			$req_uri = str_replace($pathinfo, '', rawurldecode($req_uri));
 			$req_uri = trim($req_uri, '/');
 			$req_uri = preg_replace("|^$home_path|", '', $req_uri);
+			if ( $site_path )
+				$req_uri = preg_replace("|^$site_path|", '', $req_uri);
 			$req_uri = trim($req_uri, '/');
 			$pathinfo = trim($pathinfo, '/');
 			$pathinfo = preg_replace("|^$home_path|", '', $pathinfo);
+			if ( $site_path )
+				$pathinfo = preg_replace("|^$site_path|", '', $pathinfo);
 			$pathinfo = trim($pathinfo, '/');
 			$self = trim($self, '/');
 			$self = preg_replace("|^$home_path|", '', $self);
+			if ( $site_path )
+				$self = preg_replace("|^$site_path|", '', $self);
 			$self = trim($self, '/');
 
 			// The requested permalink is in $pathinfo for path info requests and
