Helping Geeks Win the War on Technology Since 2010

Adding www to WordPress 3.0+ Multisite/MU Root Domain

March 6, 2011

If you’ve used the multisite option on WordPress 3.0 and greater, you’ll notice that you may have your ‘www’ stripped from your main blog root domain. Supposedly, WordPress 3.0 was supposed to automatically handle your ‘www’ if you had specified it properly when you made the initial installation.

But what about the rest of us who neglected to do so? It’s an easily overlooked step, and fortunately it’s easily correctable… if you’re willing to brave through digging your MySQL database and editing one line PHP code. With pre-WP 3.0 blogs you were able to specify the main site URL, but that option is gone in 3.0. So what you’ll need to do is dig around in your WordPress database and modify your wp-config.php.

We’ll take it one at a time.

Launch your myphpadmin panel and navigate to your WordPress database. Inside, there will be two tables you’ll need to modify: wp_blogs and wp_options. Alternatively, you could run a text string search for ‘mydomain.com’ through the myphpadmin interface and get those tables to appear.

Browse the table wp_blogs by clicking on it and click on the pencil icon next to edit the field of the root domain that you wish to change.

add www wordpress multisite

This will bring up a window to edit the field, you should see ‘mydomain.com’. Simply replace that with ‘www.mydomain.com’ as specified here.

add www to root domain wordpress 3.0

Do the same for the wp_options table, editing the siteurl and home entries in the table. Make similar changes, replacing any instance of http://mydomain.com with http://www.mydomain.com. Then to be thorough–though I believe I didn’t do this on a few other installations and it still worked fine–be sure to make similar modifications in the wp_site, wp_sitemeta, and wp_usermeta tables as well. There are maybe only 4 more entries total there to which you need to add a ‘www.’

add www to root domain wordpress 3.0

You’re in the home stretch now. Close myphpadmin and edit your wp-config.php file in the root directory of your WordPress installation folder. Modify the line:

define( 'DOMAIN_CURRENT_SITE', 'mydomain.com' );

to

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

and you’re done! You’ll probably have to re-login to your dashboard, but it should show the ‘www’ in the URL this time.

This fix requires no fussing with the .htaccess file. I tried this originally with just making the changes in the WordPress MySQL database only, but I ended up getting a “The page isn’t redirecting properly” error in Firefox. It turns out I was missing one critical modification in wp-config.php, which I’ve pointed out above.

Hopefully that solved any headaches for you and allowed you to add ‘www’ in your root domain of your multisite WordPress installation.

posted in WordPress by helpgeek

Follow comments via the RSS Feed | Leave a comment | Trackback URL

25 Comments to "Adding www to WordPress 3.0+ Multisite/MU Root Domain"

  1. Gurpreet wrote:

    Thank you so much i was having trouble with it and wasted my whole day
    Thanks alot
    GUrpreet

  2. helpgeek wrote:

    Gurpreet, I’m glad it helped somebody out. I went back and added a few more tables that you should probably also modify to the post. It’s complete and updated now.

  3. Oudin wrote:

    What about the sub domains would they be able to utilize this? and would it work on a mapped on domain?

  4. helpgeek wrote:

    Not sure about subdomains actually. For mapped domains you don’t need to do this, you simply mark the “www.domain.com” as the primary domain. Look up the domain mapping plugin for MU. Adding ‘www’ is only a problem to change on the root domain.

  5. J Venator wrote:

    Thanks so much for this. Right in the nick of time!

  6. Julian wrote:

    Thank you. Your solution is very effective. I waste a lot of time with the htaccess solution.

  7. mathan wrote:

    Thank you very much.. i spend more time to solve this issue. Atlast i land on your site.

  8. George wrote:

    Thanks for this but now when you type the address without the www it doesn’t redirect to the address with the www. Instead I am getting the “his webpage has a redirect loop” in Chrome.

  9. George wrote:

    Disregard last post. Got it to work now. Forgot to save the change in the wp-config file.

  10. Matt wrote:

    Thanks a lot, you have no idea how much of a headache this has been causing me these last few days!

    I’ve been trying to get it to work with a simple search & replace for http://mydomain.com for http://www.mydomain.com, only with no luck.

    Little did I realise it’s better to manually edit some of the tables (e.g. wp_blogs).

    Thanks again!

  11. Nick wrote:

    Oh man, thanks. At first i thought it was a Firefox or Google new update until i visited other sites.

    Thanks again for your knowledge, time and effort.
    Much appreciated.

  12. Nick wrote:

    Just an update! If you have multi-db plugin installed and configured you might wanna check your global database too!

  13. Kyle wrote:

    You saved me hours of headaches. I was just about to re-install a new WordPress MU site with the “www” before I found this. That would have been aweful.

  14. hamedbbs22 wrote:

    www. have good effect or bad effect on website?

  15. helpgeek wrote:

    To be honest I don’t think there is any effect, it’s more about branding and personal preference really.

  16. Raja wrote:

    Ok, I’ve managed to sort it out but I think I was more stupid than brave at giving it a go myself (being non-technical).

    So example.com now redirects to http://www.example.com but the issue is..

    http://www.example.com/blog1/ redirects to http://www.example.com
    example.com/blog1/ redirects to http://www.example.com

    http://www.example.com/blog2/ redirects to http://www.example.com
    example.com/blog2/ redirects to http://www.example.com

    I dont want my other multi-install blogs to redirect to the main domain. Is there a fix for that?

  17. helpgeek wrote:

    Raja:

    Don’t panic, you can solve this. Go to the network admin portal of your main site and click on “Sites” and then edit “blog1″ or “blog2″. There you will see the domain, which probably does not include the “www.” Try removing that and also updating the “Siteurl” and “Home” fields on the “Settings” tab. You can also try checking the checkbox that says “Update siteurl and home as well” but it made everything screwy for me. I had to do it manually by hand. After that the redirect should work fine.

  18. Raja wrote:

    Hey helpgeek.

    Thanks for the fast response. I think I really needed it. It’s nearly 2am here in the UK and still trying to get this fixed.

    Tried network admin => sites => edit domain/path.

    I think im getting there but not fully fixed.

    http://www.example.com/blog1/ redirects to http://www.example.com but
    http://www.example.com/blog1/posts/ or http://www.example.com/blog1/categories/ or anything else seem to load perfectly fine WITHOUT any redirects.

    Also example.com/blog1/posts/ or example.com/blog1/categories/ (without www.) redirects but incorrectly redirects back to root level instead of redirecting to www. of whichever page/post.

    As for ——————————–
    Try removing that and also updating the “Siteurl” and “Home” fields on the “Settings” tab. You can also try checking the checkbox that says “Update siteurl and home as well” but it made everything screwy for me. I had to do it manually by hand. After that the redirect should work fine.
    ———————

    I’ve used the “Update siteurl and home as well.” check box but it didn’t seem to do anything at all for me.

    To do it manually by hand, I can’t actually find these options under settings.

    When you say you did it, was it on geekhelpguide.com or another blog?

    Thanks in advanced.

  19. helpgeek wrote:

    It was a different blog, and I was doing the opposite, removing the “www.” At any rate it works the same, you can use the information in this post to remove www if you wanted.

    Make sure you are in the “Settings” tab, the right most one. The very first option is “Siteurl” and the field to the right of it is what you need to change. Do a search for the “Home” field too. Make sure you are logged in as the network admin account and you have permissions to make those changes.

  20. Raja wrote:

    Ok, I’ve done that under under the settings tab. Still get same results as previous comment that i posted.

    Not sure if I need to do anything with the htaccess file or config file.

    Would you say I’ve tried all solutions? Shall i just start re-installing everything from scratch?

    Cheers

  21. helpgeek wrote:

    What you may need to do is go back to your MySQL database and replace any instances of the domain in the tables for blog1 and blog2 as well. These are different from the main one as they are appended by a number (the number being their site id).

    Also check the wp_blogs and wp_options tables and make sure you exhaustively replace the instance of your root domain everywhere, not just in the fields listed in the post.

  22. Raja wrote:

    I’ve done that and checked and re-checked multiple times to ensure I havent left out anything on MySQL. Still no luck.

    I threw the towel, gave up and reinstalled all over again but this time I made sure that www was set up before creating multi site network.

    Thanks for all your help though. I’m sure other readers will find it helpful.

  23. John wrote:

    ***SOLUTION***

    I have successfully converted my multisite from non-www to www using the following method. Please be cautious and backup your db before doing it. Also read all the following instructions completely before starting the process.

    1. edit wp-config.php and change
    from
    define(‘DOMAIN_CURRENT_SITE’, ‘mydomain.com’);
    to
    define(‘DOMAIN_CURRENT_SITE’, ‘www.mydomain.com’);

    2. get the search & replace script from https://github.com/interconnectit/Search-Replace-DB and read the instructions on the site on how to use it.
    It is straightforward as explained below. Put the downloaded script in your website home folder and go to http://mydomain.com/searchreplacedb21.php
    step1: select the pre-populate the db values option and clik submit
    step2: check your pre-populated db details and click submit
    step3: select the tables (select 10 at a time: If you select all of them, the script execution time might exceed and would fail. So either select few tables at a time or increase your script execution time in your php.ini). Do not select “Leave GUID column unchanged”, so leave this unselectecd. Because this is the reason (to update GUID) we are using this script to update the db.
    step4: search for “http://mydomain.com” and replace with “http://www.mydomain.com”. ***NOTE***: here make sure to put the http:// infront of your domain in your search terms, because you will have entries in the db for folders such /home/blahblah/public_html/mydomain.com and you do not want to replace these instances. So you have to search and replace for http://mydomain.com to http://www.mydomain.com
    step5: The results shown on how many are replaced on the selected tables. Now use browser’s back button to go back to step3 and select the next set of tables and continue the process until you finish all the tables.

    3. During the search & replace process, let us say you would start search and replace from http://mydomain.com/searchreplacedb21.php and in the middle it might say permission denied. Because for the main domain the path would have already changed to http://www.mydomain.com. So if this happens visit http://www.mydomain.com/searchreplacedb21.php and restart the process and complete the search and replace for all the tables.

    4. delete the file searchreplacedb21.php from your domain.

  24. Scott L. wrote:

    I found this to be a two step process. Do all the replacing as helpgeek indicated, thoroughly, and then add this to the top of your .htacess file:

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^example.com
    RewriteRule (.*) http://www.example.com/$1 [R=301,L]

    This essentually takes whatever comes after the URL and pastes www. to the front.

    NOTES:

    (1) The command “Rewrite On” should only appear once in your .htaccess file.

    (2) If you have a plugin that does a 301 redirect you might have to edit that line manually inside WordPress.

    (3) If you have serialized plugins (meaning you purchased a license key) you might have to disable them before doing any replacing in the SQL database. This may also be true if you use John’s solution.

    Good luck All.

  25. Scott L. wrote:

    Oops… Sorry. I wrote that too fast… Corrections –

    NOTES:

    (1) I AM NOT SURE BUT I BELIEVE the command “Rewrite On” should only appear once in your .htaccess file.

    and I forgot…

    (4) This addition to your .htaccess should be BELOW this

    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ – [L]

Leave Your Comment

You must be logged in to post a comment.

 
Powered by Wordpress and MySQL on MDDHosting. Theme by Shlomi Noach, openark.org