Wanna run a WordPress Network on multiple ports?

In order to run your blog at a different URL, you will first need to make this change in your theme’s functions.php file:

remove_filter('template_redirect','redirect_canonical');

Somewhere just after the first line should be fine.

H/T velvet blues: Turn Off WordPress Homepage URL Redirection

If you are worried about negatively impacting your SEO, you can wrap it in a conditional like this:

if ($_SERVER["SERVER_PORT"] == 8888) {
remove_filter('template_redirect','redirect_canonical');
}

Assuming you have Apache setup for multiple ports, or you have a caching server like nginx or varnish in front of your Network (Multisite), you may see an error like this if you access the site on a port than 80 or 443:

'Multisite only works without the port number in the URL.'

To fix that, you just need to modify wp-includes/ms-settings.php as described in WP trac, like this:

@@ -26,18 +26,8 @@
if ( !isset( $current_site ) || !isset( $current_blog ) ) {
+        $_SERVER['HTTP_HOST'] = preg_replace( '|:\d+$|', '', $_SERVER['HTTP_HOST'] );
$domain = addslashes( $_SERVER['HTTP_HOST'] );
-        if ( false !== strpos( $domain, ':' ) ) {
-               ....
-                        wp_die( /*WP_I18N_NO_PORT_NUMBER*/'Multisite only works without the port number in the URL.'/*/WP_I18N_NO_PORT_NUMBER*/ );
-                }
-        }

Not that hard, right?

Discussion

  1. TJ Singleton says:

    Thanks! Works like a charm.

  2. Rob says:

    I came across a similar issue, but I didn’t want to mess with any of the existing redirection in wordpress. There is a function in the functions.php file that grabs all the options from the wordpress db called get_options. In there I added a line of code that checks if the request is for either the “siteurl” or “home” url options. Then I just check for the port my site is running on, so if its 80, leave as is, if its 81, hard code the 81 port.

    Full instructions are here: http://www.duchnik.com/tutorials/wordpress-on-multiple-ports/

Add a Comment

*

*