Hide root site in Multisite install

I was in a similar situation recently. I ended up putting the root site on a random subdomain (eg ms.domain.com) With the intention of never using the root site.

With that done, I created a plugin to activate only on the main (root) site.

The plugin hooks into a action that fires only on the front end (template_redirect). From there, call wp_redirect to send your visitors to where they need to be.

<?php
add_action('template_redirect', 'wpse52298_redirect');
/*
 * Redirects all requests to the front end to another site
 *
 * @uses wp_redirect
 */
function wpse52298_redirect()
{
    // change this
    $to = 'http://www.example.com';

    wp_redirect(esc_url($to));
    exit();
}

Cons:

  • Loads basically all of WP before redirecting
  • Not as fast as redirecting in htaccess

Pros:

  • Easy to maintain
  • No htaccess foo required

As a plugin.

Leave a Comment