WordPress MU – No Longer a Bare-Domain Nazi

A week or three ago I learned that WordPress MU was explicitly coded to refuse to run on a 'www' subdomain, instead forcing you to run it on the bare domain.  While running your website on the bare domain is certainly a reasonable thing to do, forcing users of your software to do it seemed, well, idiotic.  I happen to think that the 'www' subdomain is the proper place to run your website, though since the bare domain is widely used, I ensure that if you visit 'barneyb.com' you'll have exactly the same experience as if you visit 'www.barneyb.com'.

Being the good (if opinionated and occasionally obnoxious) open source aficionado that I am, after my initial reaction of outrage, I've revisted the issue and "fixed" the problem.  Aside from the install script (index-install.php), there was only one place that needed changing (in wpmu-settings.php).  The patch is below, made against WordPress mU 2.7.1:

Index: index-install.php
===================================================================
--- index-install.php   (revision 5342)
+++ index-install.php   (revision 5343)
@@ -362,8 +362,6 @@
        $weblog_title = ucfirst( $_SERVER[ 'HTTP_HOST' ] ) . ' Blogs';
        $email = '';
        $hostname = $_SERVER[ 'HTTP_HOST' ];
-       if( substr( $_SERVER[ 'HTTP_HOST' ], 0, 4 ) == 'www.' )
-               $hostname = str_replace( "www.", "", $_SERVER[ 'HTTP_HOST' ] );
        ?>
        <form method='post' action='index.php'>
                <input type='hidden' name='action' value='step2' />
@@ -511,8 +509,6 @@
        global $wpdb;
        $domain =   $wpdb->escape( $_POST[ 'basedomain' ] );
        $domain = str_replace( 'http://', '', $domain );
-       if( substr( $domain, 0, 4 ) == 'www.' )
-               $domain = substr( $domain, 4 );
        if( strpos( $domain, '/' ) )
                $domain = substr( $domain, 0, strpos( $domain, '/' ) );
        return $domain;
@@ -649,12 +645,6 @@
 $action = isset($_POST[ 'action' ]) ? $_POST[ 'action' ] : null;
 switch($action) {
        case "step2":
-               if( substr( $_POST[ 'basedomain' ], 0, 4 ) == 'www.' ) {
-                       printheader();
-                       nowww();
-                       continue;
-               }
-
                // get blog username, create wp-config.php
                step2();

@@ -662,7 +652,6 @@
                include_once('./wp-config.php');
                include_once('./wp-admin/includes/upgrade.php');

-               $_SERVER[ 'HTTP_HOST' ] = str_replace( 'www.', '', $_SERVER[ 'HTTP_HOST' ] ); // normalise hostname - no www.
                make_db_current_silent();
                populate_options();
                global $base;
Index: wpmu-settings.php
===================================================================
--- wpmu-settings.php   (revision 5342)
+++ wpmu-settings.php   (revision 5343)
@@ -6,8 +6,6 @@
 $wpmuBaseTablePrefix = $table_prefix;

 $domain = addslashes( $_SERVER['HTTP_HOST'] );
-if( substr( $domain, 0, 4 ) == 'www.' )
-       $domain = substr( $domain, 4 );
 if( strpos( $domain, ':' ) ) {
        if( substr( $domain, -3 ) == ':80' ) {
                $domain = substr( $domain, 0, -3 );

4 responses to “WordPress MU – No Longer a Bare-Domain Nazi”

  1. ƒµ©Ҝ You WordPress at BarneyBlog

    [...] (2009-05-04): I've come back and patched WordPress MU to allow the use of a 'www' subdomain.  Hopefully the change will eventually make it back to the main codebase, but I'm not holding my [...]

  2. Palma | Buddha Trance

    Barney, this no-nazi patch should be posted all over the WPMU forums… One question, what happens when one upgrades? Or once installed, it will stay this way? I have commented out the lines you mention in the patch, and also edited wp-config.php and all instances to the bare domain in the database tables, just to see if I can make it work without having to install WPMU again… still testing around. Thank you for this!

  3. Palma | Buddha Trance

    You are right, I noticed after I tested around. The core code cares only as far as two lines of code. Knowing how to patch the installer is great info for those who are starting with a fresh installation, so they don't have to go through the database and config file and change things after the fact (like I had to do).

    After that, for each upgrade it's about knowing what to look for in the settings file… thanks to you! :-)