I recently setup a WordPress multisite install using subdomains and the WordPress MU domain mapping plugin.

When I initially setup the domain mapping plugin, I set the root (http://domain.com) and http://www.domain.com to redirect to blog ID 2 (ie. www.domain.com). However, when I do this the redirect on the root prevents me from accessing the Network admin page.

Is there a way I can change the configuration to enable me to still access the Network admin page whilst redirecting the root site to www?

  • Can you remove the redirection from the domain mapping plugin, and place redirection of non-www to www in .htaccess using normal rewrite rules? – Steve May 20 '12 at 8:55
  • Shouldn't this part read like: "blog ID 2 (ie. www.another-domain.com)"? – brasofilo May 22 '12 at 10:46
up vote 0 down vote accepted
+50

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.

I recommend using this solution:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^mysite\.com$
RewriteCond %{REQUEST_URI} ^/$
Rewriterule ^(.*)$ http://mysecondsite.com/ [L,R=301]

as it preserves the root domain's subdirectories, allowing you to manage the multisite admin dashboard.

Source: How to redirect root and only root via htaccess?

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.