Moving a Network from non-www to www

First I appologize because I know some of this has been posted already but can someone give me a clear step-by-step process for changing a Wordpress Multisite install that is using the Domain Mapping Plugin and currently has a base domain of wpms.example.com to a multisite that would be using a http://www.wpms.example.com base domain.

So, I need to move it from non-www to a default www. The end goal is to have our non-www redirect to a www domain for every website in our mulitisite install.

I have read about two options:

1. Changing the wp-config.php to say:

define( 'MULTISITE', true );
define( 'SUBDOMAIN_INSTALL', true );
$base = '/';
define( 'DOMAIN_CURRENT_SITE', 'www.example.com' );
define( 'PATH_CURRENT_SITE', '/' );
define( 'SITE_ID_CURRENT_SITE', 1 );
define( 'BLOG_ID_CURRENT_SITE', 1 );

And 2. Possible adding a .htaccess file that repoints the non-www to the www.

The problem, I'm being told by my team, is that both of these create a redirect loop.

I look forward to hearing a response and thank you for taking the time to answer this.

  • DavidM

    Hi Page1Solutions and first off, welcome to WPMU DEV!

    Just to mention to start with, if you use the sub-directory install option, you can definitely use 'www' with no issues, at least as far as I've ever seen in using it for testing.

    As for sub-domains though, that's a serious difficulty because the 'www' would be recognized as a sub-domain.

    I'll have to tag a few of the other guys over here to see they know how that's done in that case, though I should mention, we can't advise using doing that given the complications surrounding it.

    -David

  • Page1Solutions

    Looking into this farther, it does seem like the www redirect is handled within the Domain Mapping plugin. Our company is an SEO organization and several years ago we decided to use the www as the base domain for our sites. Since we have been optmizing these sites for years using the www, my hand is forced to continue down that path.

    It seem like my best hope is to get a "clean" hack from your team to make the domain mapping pluing use the www and redirect the non-www.

    Thanks for your quick response!

  • Page1Solutions

    In reading the Domain Mapping Plugin files, I see five references to replacing the www. They are:

    domain-mapping\domain-mapping.php (4 hits)
    Line 383: $domain = $this->db->escape( preg_replace( "/^www\./", "", $_POST[ 'domain' ] ) );
    Line 509: $newdomain = $this->db->get_var( $this->db->prepare( "SELECT domain FROM {$this->dmt} WHERE domain = %s AND blog_id = %d LIMIT 1 /* domain mapping */", preg_replace( "/^www\./", "", $_SERVER[ 'HTTP_HOST' ] ), $this->db->blogid ) );
    Line 547: $domain = $this->db->get_var( $this->db->prepare( "SELECT domain FROM {$this->dmt} WHERE domain = %s AND blog_id = %d LIMIT 1 /* domain mapping */", preg_replace( "/^www\./", "", $_SERVER[ 'HTTP_HOST' ] ), $this->db->blogid ) );
    Line 577: $domain = $this->db->get_var( $this->db->prepare( "SELECT domain FROM {$this->dmt} WHERE domain = %s AND blog_id = %d LIMIT 1 /* domain mapping */", preg_replace( "/^www\./", "", $_SERVER[ 'HTTP_HOST' ] ), $this->db->blogid ) );

    domain-mapping\sunrise.php (1 hits)
    Line 18: $using_domain = $wpdb->escape( preg_replace( "/^www\./", "", $_SERVER[ 'HTTP_HOST' ] ) );

    I can't write or read PHP, so this is a stab in the dark -- should i make the following change to these lines of code:

    From - ( "/^www\./", "",
    To - ( "", "/^www\./",

    Essentially, just reversing the redirect?

  • Page1Solutions

    Just an FYI, this can be closed out.

    My organization was able to get this plugin to create the www as the primary domain and the non-www as the redirected domain.

    We started by commenting out this line:

    // UnComment out the line below to allow multiple domain mappings per blog
    define('DOMAINMAPPING_ALLOWMULTI', 'yes');

    This allowed us to map multiple domains within Wordpress.

    Then we mapped the domains in Apache by modifying the httpd.conf.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.