Forcing MU to use www

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.

27 Comments
  • Dr. Mike Wendell
    Posted at 13:41h, 20 June Reply

    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.

  • Pryrates
    Posted at 17:12h, 28 July Reply

    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…

  • Pryrates
    Posted at 14:01h, 29 July Reply

    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)

  • d0k
    Posted at 14:24h, 04 September Reply

    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!

  • Rijas
    Posted at 03:29h, 24 October Reply

    Hi Andrea,

    Thank you very much for this helpful information.

  • Vivek
    Posted at 05:54h, 04 February Reply

    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

  • Vivek
    Posted at 07:33h, 04 February Reply

    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

  • Luc
    Posted at 20:01h, 11 February Reply

    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!

  • vencer
    Posted at 06:22h, 23 July Reply

    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 =-.

  • ehusfera kudeatzen » WordPress-mu instalatzen
    Posted at 07:44h, 06 August Reply

    […] Bestetik, gure kasuan blogetarako ez genituen azpi domeinuak baimendu nahi. Blog bakoitza azpi-karpeta batean egotea nahi genuen. WordPress-mu instalatzean aukera hau eskaintzen da, baina berez eta ezer galdetu barik instalatzaileak domeinuaren aurreko www delakoa desagerrarazten du. Guretzako beharrezkoa da www domeinuan izatea, ziurtagiriak http://www.ehu.es domeinurako prestatuta dauzkagulako. Honetarako ondorengo artikuluan datozen argibideak jarraitu genituen: Forcing MU to use www […]

  • Ferguson Industry Inc.
    Posted at 23:30h, 01 November Reply

    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!

  • eDDi Hughes
    Posted at 20:51h, 02 November Reply

    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.

  • Wacasa
    Posted at 10:35h, 20 November Reply

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

  • Litso
    Posted at 06:48h, 23 November Reply

    Nice find, thanks a lot 🙂

  • Litso
    Posted at 07:37h, 23 November Reply

    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?

  • Ryan
    Posted at 11:12h, 30 December Reply

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

  • gilek7
    Posted at 08:49h, 16 January Reply

    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?

  • John Kolbert
    Posted at 01:31h, 10 February Reply

    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
      Posted at 09:27h, 10 February Reply

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

      • John Kolbert
        Posted at 09:38h, 10 February Reply

        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
          Posted at 09:46h, 10 February Reply

          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
      Posted at 10:38h, 17 August Reply

      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
        Posted at 10:49h, 17 August Reply

        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
          Posted at 11:45h, 17 August Reply

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

          • Ron
            Posted at 21:46h, 17 August

            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.

  • Sven Wagener
    Posted at 17:02h, 20 May Reply

    Thaaaaaanks a lot! You saved my evening 😉

    Greetings,

    Sven

Post A Comment