• Resolved aldero

    (@velegno)


    Hi,

    I was trying to change the root blog for a multisite installation. I had a lot of problems doing this and I tried a lot of different configurations. And I broke the site many times with infinite re-directions.

    At the end it worked somehow but it is still buggy. The “www” will be always removed (no I don’t have canonical urls or some redirect in htaccess or somewhere else). This breaks the comment system of jetpack for instance.

    The bottom line is simple: there should be an easy way to change the root blog of a multisite network.

    And: internally (in the database) the first blog “wp_xxxx” is strangely related to the network. They should be clearly separated. In fact the first blog should be called wp_1_xxxx. And all the network settings should be independent from this blog.

    cheers.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    πŸ³οΈβ€πŸŒˆ Advisor and Activist

    The bottom line is simple: there should be an easy way to change the root blog of a multisite network.

    There is. It’s all of like … 3 steps.

    It’s in https://store.halfelf.org/ebooks/wordpress-multisite-110/ around page 80 but basicically it’s this:

    1. Go to Network Dashboard > Sites and edit the site you want to be the main site. Change that to have the URL you want for you main site (so from example.com with a path of /sample/ to one with a path of / )

    Make certain you leave β€˜Update siteurl and home as well’ checked!

    2. Then go to your wp-config.php, look for this line:

    define('BLOG_ID_CURRENT_SITE', 1);

    Change it to the site ID you want to use as your main site.

    3. Go back to your Sites and edit the old main site. Give its path a new name and press save, making sure you keep that checkbox checked.

    After that you have to change the URLs per site for existing media and links but that’s just a search/replace of wp_x_posts for each one

    Thread Starter aldero

    (@velegno)

    Hi,

    Ok, some infos about my network:
    It has 4 blogs:

    www.mydomain.com ( currently untouched ) "holy blog"
    blog2.mydomain.com
    blog3.mydomain.com
    blog4.mydomain.com ( currently just mydomain.com )

    ****

    I’m glad that you answered. Actually I followed your instructions here:
    http://wordpress.org/support/topic/default-multisite-redirect-to-one-particular-blog?replies=8

    But unfortunately they didn’t work. I’m not saying that your instructions are bad. My hunch is that they work better for the sub-folder version, OR that they work for versions of WP previous to 3.9. (see here http://www.webhostinghero.com/wp-multisite-stuck-in-redirect-loop/)

    *** First Steps ***

    I followed the steps at least two times. Everything crashed as soon as I did the second url change (from www.mydomain.com > something.mydomain.com checkbox checked) Then the network was completely dead. I got infinite redirects everywhere. I tried to find in the DB how to set things back… but I ended restoring a backup of the DB. And all this at least three times -luckily in a development installation.

    *** SECOND STEPS ***

    After such debacle I still needed to change the root blog. I discovered that if I removed the subdomain from the secondary blog (blog4.mydomain.com > mydomain.com) while leaving the other untouched (www.mydomain.com) wordpress re-routed the main domain to that blog, “for some unknown reason”. It removes the “www” though and this breaks things. wp-config.php still is like this:

    define(‘SITE_ID_CURRENT_SITE’, 1);
    define(‘BLOG_ID_CURRENT_SITE’, 1);

    This is the current state. It works but it’s buggy.

    *** Other explanations. ***

    In one opportunity I managed to change the whole thing. As far as I can remember I did “blog4 > www” and “www > *nothing*” then I changed BLOG_ID_CURRENT_SITE to 4. BUT this broke every media path as you said. This simply makes no sense: I was not changing the media path of my blog, I was just telling WP to use a different instance as main site. How on earth should I fix the media paths without editing the DB. (That particular blog has like hundreds of pics and as you know wp_x_postmeta has serialized data that would be damaged with a simple search and replace query)

    This is simply annoying to say the least.

    *** Final thoughts ****

    Maybe I will try once again but I would need some input.

    I *think* that changing the holy blog (www.mydomain.com) with the checkbox checked does affect the routing of the whole network. “For some unknown reason”.

    I would try the following steps:

    Change blog4.mydomain.com > www.mydomain.com (checkbox checked)
    change BLOG_ID_CURRENT_SITE 1 > 4
    change www.mydomain.com > network.mydomain.com (checkbox unchecked)
    *** praise...

    Do you have any idea about why changing the holy blog with checkbox checked ends in an infinite redirect? Where are the key network domains in the DB?

    For me this opens questions for the developers:
    Why changing BLOG_ID_CURRENT_SITE affects the media path?
    Why is the holy blog “coupled” with the network?
    Why is the media path of the holy blog just wp-uploads? It should be also wp-uploads/sites/1 !

    If you are a developer or are more familiar with the community, this would be an important issue for the future development.

    Thx.

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    πŸ³οΈβ€πŸŒˆ Advisor and Activist

    Actually I tested those directions on BOTH subdomain and subfolder πŸ™‚ They work. Just tested again.

    Do you have any idea about why changing the holy blog with checkbox checked ends in an infinite redirect?

    Not a clue, it worked fine for me on 3.9 WP :/

    Depends on what you have in wp-config, but FWIW, you can do all the changes in the database.

    wp_options – This is the table for the MAIN site (original #1) so you’d look for and edit siteurl and home values

    wp_4_options – This is the table for the NEW main site (original #4) so you’d look for and edit siteurl and home values as well

    wp_blogs – This is where the blog info is kept, you’ll want to edit them there so site #1 is network and so on.

    That said… You may still need to do some search/replace in wp_options and wp_4_options.

    Why is the media path of the holy blog just wp-uploads? It should be also wp-uploads/sites/1 !

    No, site #1 is always in wp-content/uploads. It just is because of single site upgrades πŸ™‚

    The “www” will be always removed (no I don’t have canonical urls or some redirect in htaccess or somewhere else). This breaks the comment system of jetpack for instance.

    www and non-www doesn’t have any impact on Jetpack, HOWEVER that’s actually probably why you’re getting a redirect. There’s a bug in 3.9 with the www redirecting stupidly. Try changing it to NON www.

    Thread Starter aldero

    (@velegno)

    So finally I achieved the challenge. Thank you for your input.

    Here is what I did if anyone is planing to undertake the odyssey.

    Here is a summary of the final settings:

    www.mydomain.com  > network.mydomain.com  // still the "holy blog"
    blog2.mydomain.com
    blog3.mydomain.com
    blog4.mydomain.com > www.mydomain.com

    In the database:

    site:

    wp_site     -> domain  -> www.mydomain.com
    wp_sitemeta  -> siteurl -> www.mydomain.com
    wp_blogs     -> 1       -> network.mydomain.com
    wp_blogs     -> 4       -> www.mydomain.com

    holy blog:

    wp_options -> siteurl -> http://network.mydomain.com/
    wp_options -> home    -> http://network.mydomain.com/

    blog4:

    wp_4_options -> siteurl -> http://www.mydomain.com/
    wp_4_options -> home    -> http://www.mydomain.com/

    wp-config.php

    /* Multisite */
    define('MULTISITE', true);
    define('SUBDOMAIN_INSTALL', true);
    define('DOMAIN_CURRENT_SITE', 'network.mydomain.com');
    define('PATH_CURRENT_SITE', '/');
    define('SITE_ID_CURRENT_SITE', 1);
    define('BLOG_ID_CURRENT_SITE', 1);

    .htaccess

    # BEGIN fix for redirect loop #
    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^mydomain\.com$ [NC]
    RewriteRule ^(.*)$ http://www.mydomain.com/$1 [L,R=301]
    RewriteCond %{HTTP_HOST} ^mydomain\.com [NC]
    RewriteRule ^(.*) http://www.mydomain.com/$1 [L,R=301]
    </IfModule>
    # END fix for redirect loop #

    This settings get the redirection right. The most tricky part was to discover that DOMAIN_CURRENT_SITE should be set to the subdomain (network.mydomain.com) to get things to work correctly. This setting will redirect http://www.mydomain.com/wp-signup.php to network.mydomain.com/wp-signup.php

    You don’t really need to change “BLOG_ID_CURRENT_SITE” to 4. This setting would change which blog is in “control” of the network and will also break every media path. Funny, isn’t it?

    You DO need the .htaccess lines if you don’t want the infinite loop to break http://mydomain.com. This is a “bug” or a feature of WP 3.9 that seems to allow a change of the www blog, but ends in a redirect loop (see here http://www.webhostinghero.com/wp-multisite-stuck-in-redirect-loop/ ). I needed BOTH lines in the htaccess files. One is for the url with trailing slash and the other without. Your server settings might be different.

    Hope you can use this for the community. cheers!

    Thread Starter aldero

    (@velegno)

    UPDATE:

    The settings listed above worked fine but they broke my cookies >-/

    You can use them but will have to use in wp-config:

    define( 'COOKIE_DOMAIN', 'www.mydomain.com' );

    But if you are using W3 Totalcache don’t even try to change the cookies domain. You will have to use following settings:

    wp-config.php

    /* Multisite */
    define('MULTISITE', true);
    define('SUBDOMAIN_INSTALL', true);
    define('DOMAIN_CURRENT_SITE', 'www.mydomain.com');
    define('PATH_CURRENT_SITE', '/');
    define('SITE_ID_CURRENT_SITE', 1);
    define('BLOG_ID_CURRENT_SITE', 4);

    And use the htaccess:

    # BEGIN fix for redirect loop #
    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^mydomain\.com$ [NC]
    RewriteRule ^(.*)$ http://www.mydomain.com/$1 [L,R=301]
    RewriteCond %{HTTP_HOST} ^mydomain\.com [NC]
    RewriteRule ^(.*) http://www.mydomain.com/$1 [L,R=301]
    </IfModule>
    # END fix for redirect loop #

    This will set the blog 4 as your main network blog. This means that http://www.mydomain.org/wp-signup.php will not redirect to network.mydomain.com/wp-signup.php. I wanted to do this in my network but I’m using w3 Totalcache. So I got to use the main domain for the network.

    Basically the settings are like Ipstenu described here: http://wordpress.org/support/topic/default-multisite-redirect-to-one-particular-blog?replies=8 but with a htacess rewirte rule to fix the redirect loop that killed my network many times.

    cheers!

    Thread Starter aldero

    (@velegno)

    UPDATE on the UPDATE:

    I forgot that setting define(‘BLOG_ID_CURRENT_SITE’, 4); would break the media paths… Holy cow, this drives nuts…

    Final final settings (everything described above +):
    wp-config:

    /* Multisite */
    define('MULTISITE', true);
    define('SUBDOMAIN_INSTALL', true);
    define('DOMAIN_CURRENT_SITE', 'www.mydomain.com');
    define('PATH_CURRENT_SITE', '/');
    define('SITE_ID_CURRENT_SITE', 1);
    define('BLOG_ID_CURRENT_SITE', 1);

    This will cause a redirect loop when calling http://www.mydomain.com/wp-signup.php I really don’t care about this. It is by far the least evil in all this.

    Here I’m shouting to the developers: There should be an easy way to change the blog shown when calling the “www” domain.

    cheers!

    Is this just an extremely complicated way of what the person above said to do or did it have to be done this way? Thanks for posting your process.

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    πŸ³οΈβ€πŸŒˆ Advisor and Activist

    Here I’m shouting to the developers: There should be an easy way to change the blog shown when calling the “www” domain.

    Here I’m shouting back at you “No there should not.”

    http://www.domain.com and domain.com are the same thing in web terms πŸ™‚ www means “Website” like http://ftp.domain.com means “file transfer” and so on. It’s archaic, but it’s meant to be the same thing.

    Also the redirect loop with www was fixed in 3.9.1 πŸ™‚

    Thread Starter aldero

    (@velegno)

    But you know what I’m talking about:

    After that you have to change the URLs per site for existing media and links but that’s just a search/replace of wp_x_posts for each one

    Just think about it: I just changed the blog that should be shown in the main “www” subdomain. Why does this break the media paths???

    This means repairing the whole media. This task is not a simple search replace. In my case I had more than 400 images. And postmeta has serialized data. This means that I have to install a plugin and recreate all thumbnails… :/

    That has had odd issues in the past with making new sites, they get made off of that site instead of the original, so they aren’t easily visible on the back end.

    Yes there are odd issues and those odd issues have a name “bugs”. Now I don’t want to simply complain. My message is: There are things there that can be improved and instead of pretending that there are minor issues, the developers can take action. I already reported this as a suggested feature and described the problem quite good. I hope this is the whishlist for future versions.

    Thank you for your support.

    Cheers.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Multisite Change Root blog’ is closed to new replies.