by andrea

Forcing MU to use www

Please note: version 3.x and above WILL allow you to use the www. No hacks or workarounds are needed.

By default, Mu strips out the www on domain names. I’m not going to get into the debate of for or against, because at some point you just may be forced to use it for reasons beyond your immediate control. Whether you like it or not. 😀

In case you somehow missed catching the the change in the address bar, symptoms may include a redirect error when trying to view the main page, even if it installed fine, and a constant page refresh when trying to login. So watch the address bar and see if it’s adding the www.

After a few eye-bleeding hours searching the forums and the forum tags, I finally found it here. (Did you know there’s actually two ways to search? I should probably write a post on that…)

The thread is a year old and the line numbers are slightly off, but most of it still applies. The rewrite rule to strip www is no longer in the htaccess file so don’t bang your head looking for it. 😀

In my case, I did not want to reinstall again because of the setup it was more work. Here’s what I did:

– go into phpmyadmin and search for all instances of your domain name. Edit them to add the www to the domain name.

– Find wpmu-setting.php in your root folder. Comment out lines 10 and 11 like this:

// if( substr( $domain, 0, 4 ) == 'www.' )
//    $domain = substr( $domain, 4 );

Those double-slashes in front of the lines keep that code from being run.

Go test your install, it should be okay. I should also mention that I only tested this on a subfolder install. I have no idea what it does on subdomains.

#comment out code#force#hack#htaccess#redirect error#search#subfolder#www

Comments

  1. The problem isn’t one of should have it or shouldn’t have it. The problem is when a server only accepts connects with or without it. The server should be accepting connections in both cases and many of the cases in the forums, the server would only accept a connection with the ‘www’ and would drop the connection without the ‘www.’

    That’s when it’s incorrect.

  2. Pryrates

    Hey I could need some help. I tried to use WPMU 2.6 with www.

    First I tried the way you described, edited the tables with my domainname in it and commented out the two lines in wpmu-settings. But when I tried to logout I could and was always redirected to the admin panel.

    So I tried the way you linked with a new install. Commented out the two lines in wpmu-settings.php and commented out lines 238, 239, 365, 366, 451 and 487 from index-install.php and then installed with http://www.domain.tdl. But after this the loginform looked as though all css infos got lost and when I tried to login I was redirected from http://www.domain.tdl/blogs/wp-login.php to the nonexistent address http: //blogs/wp-login.php (without the space between p and /).

    And now I’m stuck…

  3. Pryrates

    I found out that the logout problem does only occur in the first login after the change without having restart the browser or emtied the cache (dunno whether this will change it)

  4. d0k

    please please please… I’ve spent two days looking for a solution for this.
    I’ve a WPMU version 2.5 installed using subdomain.
    Your advice does not work with my configuration… any advice will help..
    I really like the fact you don’t cry about standards or other stuff.. pragmatic approach is mine too!

  5. Hi Andrea,

    Thank you very much for this helpful information.

  6. hey andrea,

    Your suggestion seems working , but as i am noob with phpmyadmin, i use search and replace plugin to replace domain to add www.

    It works also, in my admin panel , it is showing with www but site is still loading with non www

    It would be nice if you can tell how to replace domain with http://www.domain with phpmyadmin

    Regards,
    Vivek

  7. hey andrea,

    I think , I hit the bulls eye, I have re-install with your tips but it didn’t work, after that i delete wp-config.php file to re-install ( only setup re-install )

    One thing i do is edit index-install.php as same code you mention is also there, comment out those two lines and re-setup

    And now my site loading with www

    hurry

  8. Luc

    I’ve managed to get this working on 2.7 – it’s much the same as your two steps, but with one extra step (and I think only required after you’ve logged in once, although I’m not sure).

    You need to edit /wp-config.php – there’s a reference to your domain without the “www” in there (line 39), that needs updating with “www.”. I needed to download, delete, edit and upload the file – it was locked by whatever user created it.

    This is on a folder setup, not sub-domain.

    Thanks!

  9. hi. i don’t really need to force MU to use www, however my problem is that when it links to http://www.domain.com/page, the site redirects to http://www.domain.com instead of domain.com/page

    do u have a simple solution for this?
    .-= vencer´s last blog ..TV Coverage of July 10 Youth Action Day vs Cha-cha =-.

  10. I installed wordpress mu on my website and followed the instructions to install also the plugins, it seems that the created url is broken, no wordpress mu files we’re copied on the directory. Please help me.

    http://test.idevelopment-tech.com/wordpressmu/

    You can register here:
    http://www.idevelopment-tech.com/wordpressmu/

    Thanks in advance!

  11. Andrea,

    Thanks for this write-up. No seriously, you seem to be the person to ask when things go hay-wire. I really appreciate the information you have provided in recent months.

  12. damn u have informations here others wouldn´give witouht money. keep up the good work. many thanx from casablanca the real city of love

  13. Litso

    Nice find, thanks a lot 🙂

  14. Litso

    On a second note, apparently I can’t login anymore on the mapped domain.

    newdomain.com is mapped to new.maindomain.com, all works smoothly. Unfortunately, when I try to login on newdomain.com/wp-admin/ I’m stuck in a redirect to the login page. Because I edited the blog’s domain settings as well I can no longer login to new.maindomain.com/wp-admin/ either

    The only thing I can do now is login to maindomain.com (the wpmu root) and edit stuff as admin, but I want to have users that can only access newdomain.com so I can’t allow them to login at the root..

    what to do?

  15. Ryan

    This fix doesn’t work with the current version of wordpress MU

  16. gilek7

    Thank you so much for all this generous help!
    I would greatly appreciate if there was any update on the current situation. The latest trunk still strips www from the URL:
    http://trac.mu.wordpress.org/browser/trunk/wpmu-settings.php
    Is there any hope this will change, or reason why not?

  17. Here’s how I did this for subdomains (NOT tested on subfolder style), WP 3.0-alpha w/multi site enabled. This adds www to your main site, but doesn’t touch subdomains.

    Add the “www” to “domain” & “site url” settings of the main blog (Network -> Sites -> Edit). I then added the following to my .htaccess: (let’s see how code shows up in the comments)

    #redirect to www for the main site
    RewriteCond %{HTTP_HOST} ^domain.com
    RewriteRule ^ http://www.domain.com%{REQUEST_URI} [L,R=301]

    Obviously change “domain” to your domain. Again, I ONLY tested this on subdomains, and it worked good.

    • andrea

      In 3.0 the code isn’t there to strip out the www. 🙂

      • Right, but if you try going to www after enabling your site it trys to take you to the bog registration form. Plus all the admin emails don’t include the www regardless of your site URL settings, so it is quite annoying unless you include those lines in your .htaccess

        • andrea

          Yep.

          But now you can install it with the www from the start. When this post was written, you could not. MU woudl strip out the www regardless of what was done.

          in 3.0 it’s all been fixed.

    • Eglwolf

      I tried this, however in the 3.01 WPMU I go to Super Admin > Sites> Edit (for the main domain) and it will not let me edit the domain or site URL. Is this the correct location or where else should I make the change.

      I have the .htaccess setup.

      • andrea

        This post is no longer relevant for 3.x. It will allow the www as long as that’s the main domain you installed on. (as opposed to using the non-www version)

        • Eglwolf

          OK, so I set the network up without the www. should I redo my network to include the http://www.?

          • Ron

            WordPress will respond to the www. (as did MU). If you want to force it on the www then change your site & home URL to www before installing the network. If you force it on the www, a WordPress network won’t respond to the non-www URL.

  18. Thaaaaaanks a lot! You saved my evening 😉

    Greetings,

    Sven

Leave a Reply

Your email address will not be published / Required fields are marked *