Wordpress MU Stubornly Forces No WWW Subdomains – Huh? And How To Fix It.

27 Nov

Let me preface by saying that I very much prefer the look and simplicity of naked domains – i.e. http://example.com vs http://www.example.com – and everything I do I try to use naked domains.

The devs working on Wordpress Multi-User, or MU, have similar thoughts on the no-www domain preference, but do they kindly make their case with suggestions and education? No, they ram the no-www mantra down your throat, hardcoding multiple and irreversible blocks of code in the setup and load scripts that expressly forbid a user from ever using a www. subdomain! Their reasoning for this seamingly arbitrary dictation? I can’t seem to find one that isn’t based on their own personal preferences.

For the most part, the MU community seems to agree with this decision as a sound one! Wow, does anyone else see a major lapse in judgement here? Here’s an abbreviated forum thread on the subject, names removed to protect the innocent:

Smart Person: Wordpress MU forcess no-www. This is a huge mistake!

Person 1: Set up your server to forward www to non-www, everything will be ok

Smart Person: No, it won’t. Why should I change my entire site structure to accomodate this arbitrary decision?

Person: Do redirects and xml sitemaps so that google re-indexes your site with no www.

Smart Person: You’re missing the point! I want a subdomain!

Person: So install MU on a subdomain like ‘blogs.example.com’

Smart Person: *sigh* ok, how about this subdomain – ‘www.example.com’!?

It just seems so silly to me that they have an unfounded, non-technical bias against ‘www’ as a subdomain. They support any other subdomain except for ‘www’!

A hack to fix this on install

Warning: This is definitely just a ‘hack’ and will most likely break on upgrade! And unfortunately, I was unable to revers the no-www effects after a complete installation, this has to be done before a fresh install.

This is for version 2.6.

In index-install.php make the following changes:

# comment out lines 238, 239:
	//if( substr( $_SERVER[ 'HTTP_HOST' ], 0, 4 ) == 'www.' )
		//$hostname = str_replace( "www.", "", $_SERVER[ 'HTTP_HOST' ] );

# comment out lines 365, 366:
	//if( substr( $domain, 0, 4 ) == 'www.' )
		//$domain = substr( $domain, 4 );

# comment out lines 475-482:
		/*
		if( substr( $_POST[ 'basedomain' ], 0, 4 ) == 'www.' ) {
			printheader();
			nowww();
			continue;
		}
		*/
# comment out line 489:
		//$_SERVER[ 'HTTP_HOST' ] = str_replace( 'www.', '', $_SERVER[ 'HTTP_HOST' ] );

In wpmu-settings.php make the following changes:

# comment out lines 9, 10:
//if( substr( $domain, 0, 4 ) == 'www.' )
	//$domain = substr( $domain, 4 );
  • Non www's are bad. www is good for seo. At least every test i've seen. Check this out... (not sure what will happen here)

    Check out this cool site I'm about to show!!

    wordpress.org/
    www.wordpress.org/

    Oh snap!
  • I'm having a hell of a time with my WPMU site not having a www.* format, specifically with google. It refuses to index the base domain without the www. To change this behavior, you have to use the webmaster tools to change your domain's format (with or without the www. when indexing).. This would be fine, however they require BOTH the www. and base domain to be activated in order to prove you own both the base, and www. sub. BUT with WPMU, the www. is not valid, and cannot have it verified in webmaster tools.. because of this, you are totally screwed. The subs all index fine, it's just the base that has the problems.
  • Tiny
    Many thanks.
    I've been working on this problem for several days, until I read your article.
    No-www does make no sense!!
  • Interesting issue. Non-www domains are pretty sexy, but the cost of switching an entire site's URL structure is something that should not be taken lightly. Nice workaround to fix what shouldn't be broken in the first place.
blog comments powered by Disqus