How to Use www in Your Domain Name in WordPress Multisite
Working with one of my WordPress (WP) sites I ran into the following problem. When I set up multisite network, my main site behaved strangely: typing www.mysite.com in the browser address bar caused the site address to be displayed without www, and subsequent navigation within the site kept the address displayed without www. One inconvenience resulting from this was that even though I had specified the preferred site in Google Search Console with www, most statistical data was shown for the site version without www.
Well, here are the steps I took to remedy this problem:
In the WP database the following statements were executed (xxx stands for the sub-directory where my site lives on the server):
update wp_site set domain = 'www.mysite.com' where domain = 'mysite.com';
update wp_sitemeta set meta_value = 'http://www.mysite.com/xxx/' where meta_key = 'siteurl';
update wp_options set option_value = 'http://www.mysite.com/xxx' where option_name = 'siteurl';
update wp_options set option_value = 'http://www.mysite.com' where option_name = 'home';
update wp_blogs set domain = 'www.mysite.com' where domain = 'mysite.com';
Added the following lines to wp-config.php:
define('NOBLOGREDIRECT', 'http://www.mysite.com'); Please note: the http:// part is very important! Putting just "www.mysite.com" will lead to an error if you type mysite.com (i.e. without www) in the browser address bar:
Firefox: The page isn't redirecting properly
Google Chrome: This webpage has a redirect loop, ERR_TOO_MANY_REDIRECTS
Safari: Safari can't open the page, too many redirects occurred trying to open...
All browsers thought I was trying to go to mysite.com/www.mysite.com
Eventually, using a slightly different set of search terms in Google, I found this:
http://wpengine.com/support/how-to-change-a-multi-site-primary-domain/, but the "wp_#_options" recommendation is not necessary if you are just trying to add the www. The site also has some instruction on changing the WP database if you are unfamiliar with how to do that.