Index: wp-includes/link-template.php
===================================================================
--- wp-includes/link-template.php	(revision 21469)
+++ 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 . '://' . $current_site->domain . $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 21469)
+++ wp-includes/ms-load.php	(working copy)
@@ -142,6 +142,12 @@
 		$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 21469)
+++ wp-includes/ms-functions.php	(working copy)
@@ -1142,7 +1142,7 @@
 
 	$wpdb->suppress_errors(false);
 
-	$url = get_blogaddress_by_id($blog_id);
+	$homeurl = $siteurl = untrailingslashit( get_blogaddress_by_id( $blog_id ) );
 
 	// Set everything up
 	make_db_current_silent( 'blog' );
@@ -1150,10 +1150,12 @@
 	populate_roles();
 	$wp_roles->_init();
 
-	$url = untrailingslashit( $url );
-	// fix url.
-	update_option('siteurl', $url);
-	update_option('home', $url);
+	// Maybe fix url
+	if ( defined( 'WP_SITEURL_SUBDIR' ) && WP_SITEURL_SUBDIR )
+		$siteurl = untrailingslashit( $siteurl ) . WP_SITEURL_SUBDIR;
+
+	update_option('siteurl', $siteurl);
+	update_option('home', $homeurl);
 	update_option('fileupload_url', $url . "/files" );
 	update_option('upload_path', UPLOADBLOGSDIR . "/$blog_id/files");
 	update_option('blogname', stripslashes( $blog_title ) );
@@ -1161,10 +1163,9 @@
 	$wpdb->update( $wpdb->options, array('option_value' => ''), array('option_name' => 'admin_email') );
 
 	// remove all perms
-	$wpdb->delete( $wpdb->usermeta, array( 'meta_key' => $table_prefix.'user_level' ) );
+	$wpdb->delete( $wpdb->usermeta, array( 'meta_key' => $table_prefix . 'user_level'   ) );
+	$wpdb->delete( $wpdb->usermeta, array( 'meta_key' => $table_prefix . 'capabilities' ) );
 
-	$wpdb->delete( $wpdb->usermeta, array( 'meta_key' => $table_prefix.'capabilities' ) );
-
 	$wpdb->suppress_errors( false );
 }
 
Index: wp-includes/ms-default-constants.php
===================================================================
--- wp-includes/ms-default-constants.php	(revision 21469)
+++ 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 21469)
+++ 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>';
@@ -314,21 +307,25 @@
  * @since 3.0.0
  */
 function network_step2( $errors = false ) {
-	global $base, $wpdb;
-	$hostname = get_clean_basedomain();
+	global $wpdb;
 
-	if ( ! isset( $base ) )
-		$base = trailingslashit( stripslashes( dirname( dirname( $_SERVER['SCRIPT_NAME'] ) ) ) );
+	$hostname          = get_clean_basedomain();
+	$slashed_home      = trailingslashit( get_option( 'home'    ) );
+	$slashed_siteurl   = trailingslashit( get_option( 'siteurl' ) );
+	$wp_siteurl_subdir = '/' . str_replace( $slashed_home, '', $slashed_siteurl );
+	$rewrite_base      = ! empty( $wp_siteurl_subdir ) ? trailingslashit( $wp_siteurl_subdir ) : '';
+	$base              = parse_url( $slashed_home, PHP_URL_PATH );
 
 	// Wildcard DNS message.
 	if ( is_wp_error( $errors ) )
 		echo '<div class="error">' . $errors->get_error_message() . '</div>';
 
-	if ( $_POST ) {
-		if ( allow_subdomain_install() )
+	if ( ! empty( $_POST ) ) {
+		if ( allow_subdomain_install() ) {
 			$subdomain_install = allow_subdirectory_install() ? ! empty( $_POST['subdomain_install'] ) : true;
-		else
+		} else {
 			$subdomain_install = false;
+		}
 	} else {
 		if ( is_multisite() ) {
 			$subdomain_install = is_subdomain_install();
@@ -344,7 +341,7 @@
 		}
 	}
 
-	if ( $_POST || ! is_multisite() ) {
+	if ( ! empty( $_POST ) || ! is_multisite() ) {
 ?>
 		<h3><?php esc_html_e( 'Enabling the Network' ); ?></h3>
 		<p><?php _e( 'Complete the following steps to enable the features for creating a network of sites.' ); ?></p>
@@ -369,20 +366,22 @@
 				<textarea class="code" readonly="readonly" cols="100" rows="7">
 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 ) {
-		if ( defined( $c ) )
+		if ( defined( $c ) ) {
 			unset( $keys_salts[ $c ] );
+		}
 	}
+
 	if ( ! empty( $keys_salts ) ) {
 		$keys_salts_str = '';
-		$from_api = wp_remote_get( 'https://api.wordpress.org/secret-key/1.1/salt/' );
+		$from_api       = wp_remote_get( 'https://api.wordpress.org/secret-key/1.1/salt/' );
 		if ( is_wp_error( $from_api ) ) {
 			foreach ( $keys_salts as $c => $v ) {
 				$keys_salts_str .= "\ndefine( '$c', '" . wp_generate_password( 64, true, true ) . "' );";
@@ -465,11 +464,11 @@
                 </rule>
                 <rule name="WordPress Rule 5" stopProcessing="true">
                     <match url="^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*)" ignoreCase="false" />
-                    <action type="Rewrite" url="{R:1}" />
+                    <action type="Rewrite" url="' . $rewrite_base . '{R:1}" />
                 </rule>
                 <rule name="WordPress Rule 6" stopProcessing="true">
                     <match url="^([_0-9a-zA-Z-]+/)?(.*\.php)$" ignoreCase="false" />
-                    <action type="Rewrite" url="{R:2}" />
+                    <action type="Rewrite" url="' . $rewrite_base . '{R:2}" />
                 </rule>
                 <rule name="WordPress Rule 7" stopProcessing="true">
                     <match url="." ignoreCase="false" />
@@ -504,13 +503,14 @@
 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 ) {
+			$htaccess_file .= "\nRewriteRule  ^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*) $rewrite_base$1 [L]\nRewriteRule  ^[_0-9a-zA-Z-]+/(.*\.php)$ $rewrite_base$1 [L]";
+		}
 
 		$htaccess_file .= "\nRewriteRule . index.php [L]";
 
 		?>
-		<li><p><?php printf( __( 'Add the following to your <code>.htaccess</code> file in <code>%s</code>, replacing other WordPress rules:' ), ABSPATH ); ?></p>
+		<li><p><?php printf( __( 'Add the following to your <code>.htaccess</code> file in <code>%s</code>, replacing other WordPress rules:' ), trailingslashit( str_replace( trailingslashit( $wp_siteurl_subdir ), '', ABSPATH ) ) ); ?></p>
 		<textarea class="code" readonly="readonly" cols="100" rows="<?php echo $subdomain_install ? 11 : 16; ?>">
 <?php echo esc_textarea( $htaccess_file ); ?></textarea></li>
 		</ol>
@@ -523,24 +523,26 @@
 	}
 }
 
-if ( $_POST ) {
+if ( ! empty( $_POST ) ) {
 
-	$base = trailingslashit( stripslashes( dirname( dirname( $_SERVER['SCRIPT_NAME'] ) ) ) );
-
 	check_admin_referer( 'install-network-1' );
 
 	require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
+
 	// create network tables
 	install_network();
-	$hostname = get_clean_basedomain();
+
+	$base              = parse_url( trailingslashit( get_option( 'home' ) ), PHP_URL_PATH );
 	$subdomain_install = allow_subdomain_install() ? !empty( $_POST['subdomain_install'] ) : false;
+
 	if ( ! network_domain_check() ) {
 		$result = populate_network( 1, get_clean_basedomain(), sanitize_email( $_POST['email'] ), stripslashes( $_POST['sitename'] ), $base, $subdomain_install );
 		if ( is_wp_error( $result ) ) {
-			if ( 1 == count( $result->get_error_codes() ) && 'no_wildcard_dns' == $result->get_error_code() )
+			if ( 1 == count( $result->get_error_codes() ) && 'no_wildcard_dns' == $result->get_error_code() ) {
 				network_step2( $result );
-			else
+			} else {
 				network_step1( $result );
+			}
 		} else {
 			network_step2();
 		}
Index: wp-admin/network/site-new.php
===================================================================
--- wp-admin/network/site-new.php	(revision 21469)
+++ wp-admin/network/site-new.php	(working copy)
@@ -62,10 +62,10 @@
 
 	if ( is_subdomain_install() ) {
 		$newdomain = $domain . '.' . preg_replace( '|^www\.|', '', $current_site->domain );
-		$path = $base;
+		$path      = $current_site->path;
 	} else {
 		$newdomain = $current_site->domain;
-		$path = $base . $domain . '/';
+		$path      = $current_site->path . $domain . '/';
 	}
 
 	$password = 'N/A';
