Running WordPress Multisite on Different Port


If are running a WordPress multiste and you run into this error:

Multisite only works without the port number in the URL.

You can make the following small change to wp-includes/ms-settings.php to include your custom port. Let’s use port 8080 as an example.

Edit: This no longer works for WordPress version 3.7 or higher.  Just a heads up! 
Change this:

if ( false !== strpos( $domain, ':' ) ) {
if ( substr( $domain, -3 ) == ':80' ) {
$domain = substr( $domain, 0, -3 );
$_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -3 );
} elseif ( substr( $domain, -4 ) == ':443' ) {
$domain = substr( $domain, 0, -4 );
$_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -4 );
} else {
wp_load_translations_early();
wp_die( __( 'Multisite only works without the port number in the URL.' ) );
}
}

To this:

if ( false !== strpos( $domain, ':' ) ) {
if ( substr( $domain, -3 ) == ':80' ) {
$domain = substr( $domain, 0, -3 );
$_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -3 );
} elseif ( substr( $domain, -4 ) == ':443' ) {
$domain = substr( $domain, 0, -4 );
$_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -4 );
} elseif ( substr( $domain, -5 ) == ':8080' ) {
$domain = substr( $domain, 0, -5 );
$_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -5 );
} else {
wp_load_translations_early();
wp_die( __( 'Multisite only works without the port number in the URL.' ) );
}
}

If your port is 5 characters long, like 18080, then you’d use something like:

} elseif ( substr( $domain, -6 ) == ':18080' ) {
$domain = substr( $domain, 0, -6 );
$_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -6 );

And if it’s 2 characters long, like 81, then you’d use something like:

} elseif ( substr( $domain, -3 ) == ':81' ) {
$domain = substr( $domain, 0, -3 );
$_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -3 );

Make sense?