Index: wp-includes/link-template.php
===================================================================
--- wp-includes/link-template.php	(revision 21424)
+++ wp-includes/link-template.php	(working copy)
@@ -2129,7 +2129,7 @@
 	if ( 'relative' == $scheme )
 		$url = $current_site->path;
 	else
-		$url = $scheme . '://' . $current_site->domain . $current_site->path;
+		$url = $scheme . '://' . trailingslashit( $current_site->domain ) . trailingslashit( $current_site->wp_siteurl_subdir );
 
 	if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
 		$url .= ltrim($path, '/');
Index: wp-includes/ms-load.php
===================================================================
--- wp-includes/ms-load.php	(revision 21424)
+++ wp-includes/ms-load.php	(working copy)
@@ -142,6 +142,10 @@
 		$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;
+		if( defined( 'WP_SITEURL_SUBDIR' ) )
+			$current_site->wp_siteurl_subdir = WP_SITEURL_SUBDIR;
+		else
+			$current_site->wp_siteurl_subdir = $current_site->path;
 		if ( defined( 'BLOG_ID_CURRENT_SITE' ) )
 			$current_site->blog_id = BLOG_ID_CURRENT_SITE;
 		elseif ( defined( 'BLOGID_CURRENT_SITE' ) ) // deprecated.
Index: wp-includes/ms-functions.php
===================================================================
--- wp-includes/ms-functions.php	(revision 21424)
+++ wp-includes/ms-functions.php	(working copy)
@@ -1150,9 +1150,13 @@
 	populate_roles();
 	$wp_roles->_init();
 
-	$url = untrailingslashit( $url );
+	$url = $siteurl = untrailingslashit( $url );
 	// fix url.
-	update_option('siteurl', $url);
+	if ( defined( 'WP_SITEURL_SUBDIR' ) && WP_SITEURL_SUBDIR ) {
+		$siteurl = trailingslashit( $siteurl ) . WP_SITEURL_SUBDIR;
+	} 
+		
+	update_option('siteurl', $siteurl);
 	update_option('home', $url);
 	update_option('fileupload_url', $url . "/files" );
 	update_option('upload_path', UPLOADBLOGSDIR . "/$blog_id/files");
Index: wp-includes/ms-default-constants.php
===================================================================
--- wp-includes/ms-default-constants.php	(revision 21424)
+++ wp-includes/ms-default-constants.php	(working copy)
@@ -47,7 +47,7 @@
 	 * @since 1.5.0
 	 */
 	if ( !defined( 'SITECOOKIEPATH' ) )
-		define( 'SITECOOKIEPATH', $current_site->path );
+		define( 'SITECOOKIEPATH', $current_site->wp_siteurl_subdir );
 
 	/**
 	 * @since 2.6.0
Index: wp-admin/network.php
===================================================================
--- wp-admin/network.php	(revision 21424)
+++ wp-admin/network.php	(working copy)
@@ -51,8 +51,8 @@
  * @return bool Whether subdomain install is allowed
  */
 function allow_subdomain_install() {
-	$domain = preg_replace( '|https?://([^/]+)|', '$1', get_option( 'siteurl' ) );
-	if( false !== strpos( $domain, '/' ) || 'localhost' == $domain || preg_match( '|[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+|', $domain ) )
+	$domain = preg_replace( '|https?://([^/]+)|', '$1', get_option( 'home' ) );
+	if( parse_url( get_option( 'home' ), PHP_URL_PATH ) || 'localhost' == $domain || preg_match( '|^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$|', $domain ) )
 		return false;
 
 	return true;
@@ -144,13 +144,6 @@
 function network_step1( $errors = false ) {
 	global $is_apache;
 
-	if ( get_option( 'siteurl' ) != get_option( 'home' ) ) {
-		echo '<div class="error"><p><strong>' . __('ERROR:') . '</strong> ' . sprintf( __( 'Your <strong>WordPress address</strong> must match your <strong>Site address</strong> before creating a Network. See <a href="%s">General Settings</a>.' ), esc_url( admin_url( 'options-general.php' ) ) ) . '</p></div>';
-		echo '</div>';
-		include ( ABSPATH . 'wp-admin/admin-footer.php' );
-		die();
-	}
-
 	if ( defined('DO_NOT_UPGRADE_GLOBAL_TABLES') ) {
 		echo '<div class="error"><p><strong>' . __('ERROR:') . '</strong> ' . __( 'The constant DO_NOT_UPGRADE_GLOBAL_TABLES cannot be defined when creating a network.' ) . '</p></div>';
 		echo '</div>';
@@ -316,9 +309,10 @@
 function network_step2( $errors = false ) {
 	global $base, $wpdb;
 	$hostname = get_clean_basedomain();
+	$wp_siteurl_subdir = str_replace( trailingslashit( home_url() ), '', site_url() );
 
 	if ( ! isset( $base ) )
-		$base = trailingslashit( stripslashes( dirname( dirname( $_SERVER['SCRIPT_NAME'] ) ) ) );
+		$base = parse_url( trailingslashit( get_option( 'home' ) ), PHP_URL_PATH );
 
 	// Wildcard DNS message.
 	if ( is_wp_error( $errors ) )
@@ -366,14 +360,15 @@
 					echo ' <strong>' . __('Warning:') . ' ' . __( 'Networks may not be fully compatible with custom wp-content directories.' ) . '</strong>';
 			?></p></li>
 			<li><p><?php printf( __( 'Add the following to your <code>wp-config.php</code> file in <code>%s</code> <strong>above</strong> the line reading <code>/* That&#8217;s all, stop editing! Happy blogging. */</code>:' ), ABSPATH ); ?></p>
-				<textarea class="code" readonly="readonly" cols="100" rows="7">
+				<textarea class="code" readonly="readonly" cols="100" rows="8">
 define('MULTISITE', true);
 define('SUBDOMAIN_INSTALL', <?php echo $subdomain_install ? 'true' : 'false'; ?>);
 $base = '<?php echo $base; ?>';
 define('DOMAIN_CURRENT_SITE', '<?php echo $hostname; ?>');
 define('PATH_CURRENT_SITE', '<?php echo $base; ?>');
 define('SITE_ID_CURRENT_SITE', 1);
-define('BLOG_ID_CURRENT_SITE', 1);</textarea>
+define('BLOG_ID_CURRENT_SITE', 1);
+define('WP_SITEURL_SUBDIR', '<?php echo $wp_siteurl_subdir; ?>');</textarea>
 <?php
 	$keys_salts = array( 'AUTH_KEY' => '', 'SECURE_AUTH_KEY' => '', 'LOGGED_IN_KEY' => '', 'NONCE_KEY' => '', 'AUTH_SALT' => '', 'SECURE_AUTH_SALT' => '', 'LOGGED_IN_SALT' => '', 'NONCE_SALT' => '' );
 	foreach ( $keys_salts as $c => $v ) {
@@ -504,8 +499,10 @@
 RewriteRule ^ - [L]';
 
 		// @todo custom content dir.
-		if ( ! $subdomain_install )
-			$htaccess_file .= "\nRewriteRule  ^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*) $1 [L]\nRewriteRule  ^[_0-9a-zA-Z-]+/(.*\.php)$ $1 [L]";
+		if ( ! $subdomain_install ) {
+			$base =  empty( $wp_siteurl_subdir ) ? '' : trailingslashit( $wp_siteurl_subdir );
+			$htaccess_file .= "\nRewriteRule  ^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*) $base$1 [L]\nRewriteRule  ^[_0-9a-zA-Z-]+/(.*\.php)$ $base$1 [L]";
+		}
 
 		$htaccess_file .= "\nRewriteRule . index.php [L]";
 
@@ -525,7 +522,7 @@
 
 if ( $_POST ) {
 
-	$base = trailingslashit( stripslashes( dirname( dirname( $_SERVER['SCRIPT_NAME'] ) ) ) );
+	$base = parse_url( trailingslashit( get_option( 'home' ) ), PHP_URL_PATH );
 
 	check_admin_referer( 'install-network-1' );
 
