Changeset 912

Show
Ignore:
Timestamp:
03/12/07 14:40:14 (2 years ago)
Author:
donncha
Message:

Don't auto-redirect to non-www hostname
Strip "www." from all urls
Added "no www" page to install
Can now install from url starting with "www."

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/htaccess.dist

    r892 r912  
    22RewriteBase BASE/ 
    33 
    4 # Rewrite www.domain.com to domain.com 
    5 RewriteCond %{HTTP_HOST} ^www\.(.*) 
    6 RewriteRule ^(.*)       http://%1/$1 [R,L] 
    74 
    85#uploaded files 
  • trunk/index-install.php

    r908 r912  
    1111 
    1212function printheader() { 
    13         if( substr( $_SERVER[ 'SERVER_NAME' ], 0, 4 ) == 'www.' ) { 
    14                 $url = 'http://' . str_replace( 'www.', '', $_SERVER[ 'SERVER_NAME' ] ) . $_SERVER[ 'REQUEST_URI' ]; 
    15                 print "<html><head><title>WordPress MU Installer</title><body>"; 
    16                 print "<p style='margin-left: 20%; margin-right: 20%; margin-top: 5%; text-align: center'><strong>Warning!</strong> WordPress MU must be installed without the 'www.' in the URL.<br />Please click here to continue the install: <a href='$url'>$url</a></p></body></html>"; 
    17                 die(); 
    18         } 
    19         print ' 
     13?> 
    2014<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    2115<html xmlns="http://www.w3.org/1999/xhtml"> 
     
    2418        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    2519        <style media="screen" type="text/css"> 
    26         <!-- 
    2720        html { 
    2821                background: #eee; 
     
    6760    text-decoration: underline; 
    6861} 
    69         --> 
    7062        </style> 
    7163</head> 
     
    7365 
    7466<h1><img src="wp-includes/images/wordpress-mu.png" alt="WordPress MU" /></h1> 
    75 '; 
     67<?php 
    7668} 
    7769 
     
    235227} 
    236228 
    237 function printstep1form( $dbname = 'wordpress', $uname = 'username', $pwd = 'password', $dbhost = 'localhost', $prefix = 'wp_' ) { 
     229function printstep1form( $dbname = 'wordpress', $uname = 'username', $pwd = 'password', $dbhost = 'localhost', $vhost = 'yes', $prefix = 'wp_' ) { 
    238230        $weblog_title = 'My new WPMU Blog'; 
    239231        $email = ''; 
    240         $hostname = str_replace( "www.", "", $_SERVER[ 'HTTP_HOST' ] ); 
    241     print " 
     232        if( substr( $_SERVER[ 'HTTP_HOST' ], 0, 4 ) == 'www.' ) 
     233                $hostname = str_replace( "www.", "", $_SERVER[ 'HTTP_HOST' ] ); 
     234    ?> 
    242235    <form method='post' action='index.php'>  
    243236    <input type='hidden' name='action' value='step2'> 
    244237    <h2>Blog Addresses</h2> 
    245238        <p>Please choose whether you would like blogs for the MU install to use sub-domains or sub-directories. You can not change this later. We recommend sub-domains.</p> 
    246         <p><label><input type='radio' name='vhost' value='yes' checked /> Sub-domains (like <code>blog1.example.com</code>)</label><br /> 
    247         <label><input type='radio' name='vhost' value='no' /> Sub-directories (like <code>example.com/blog1</code></label></p> 
     239        <p><label><input type='radio' name='vhost' value='yes' <?php if( $vhost == 'yes' ) echo 'checked '; ?> /> Sub-domains (like <code>blog1.example.com</code>)</label><br /> 
     240        <label><input type='radio' name='vhost' value='no' <?php if( $vhost == 'no' ) echo 'checked '; ?> /> Sub-directories (like <code>example.com/blog1</code></label></p> 
    248241         
    249242    <h2>Database</h2> 
     
    253246    <tr>  
    254247      <th scope='row' width='33%'>Database Name</th>  
    255       <td><input name='dbname' type='text' size='45' value='$dbname' /></td>   
     248      <td><input name='dbname' type='text' size='45' value='<?php echo $dbname ?>' /></td>   
    256249    </tr>  
    257250    <tr>  
    258251      <th scope='row'>User Name</th>  
    259       <td><input name='uname' type='text' size='45' value='$uname' /></td>  
     252      <td><input name='uname' type='text' size='45' value='<?php echo $uname ?>' /></td>  
    260253    </tr>  
    261254    <tr>  
    262255      <th scope='row'>Password</th>  
    263       <td><input name='pwd' type='text' size='45' value='$pwd' /></td>  
     256      <td><input name='pwd' type='text' size='45' value='<?php echo $pwd ?>' /></td>  
    264257    </tr>  
    265258    <tr>  
    266259      <th scope='row'>Database Host</th>  
    267       <td><input name='dbhost' type='text' size='45' value='$dbhost' /></td>  
     260      <td><input name='dbhost' type='text' size='45' value='<?php echo $dbhost ?>' /></td>  
    268261    </tr> 
    269262  </table>  
    270263  <h2>Server Address</h2> 
    271   <p><label>What is the Internet address of your site? You should enter the shortest address possible. For example, use <em>example.com</em> instead of <em>www.example.com</em> but if you are going to use an address like <em>blogs.example.com</em> then enter that unaltered in the box below.<br /><b>Server Address:</b> <input type='text' name='basedomain' value='{$hostname}'></label></p> 
     264  <p><label>What is the Internet address of your site? You should enter the shortest address possible. For example, use <em>example.com</em> instead of <em>www.example.com</em> but if you are going to use an address like <em>blogs.example.com</em> then enter that unaltered in the box below.<br /><b>Server Address:</b> <input type='text' name='basedomain' value='<?php echo $hostname ?>'></label></p> 
    272265  <h2>Blog Details</h2> 
    273266  <table width='100%'>  
    274267  <tr>  
    275268  <th scope='row'>Weblog&nbsp;Title</th>  
    276   <td><input name='weblog_title' type='text' size='45' value='".$weblog_title."' /></td>  
     269  <td><input name='weblog_title' type='text' size='45' value='<?php echo $weblog_title ?>' /></td>  
    277270  <td>What would you like to call your weblog? </td>  
    278271  </tr>  
    279272  <tr>  
    280273  <th scope='row'>Email</th>  
    281   <td><input name='email' type='text' size='45' value='".$email."' /></td>  
     274  <td><input name='email' type='text' size='45' value='<?php echo $email ?>' /></td>  
    282275  <td>Your email address.</td>  
    283276  </tr>  
    284277  </table>  
    285278  <p class='submit'><input name='submit' type='submit' value='Submit' /> </p> 
    286 </form> "; 
     279</form>  
     280<?php 
    287281} 
    288282 
     
    349343        print "<b style='color: #00aa00; font-weight: bold'>DONE</b><br />"; 
    350344        define( 'VHOST', $vhost ); 
    351 } 
    352  
    353 function printuserdetailsform( $weblog_title = 'My new Blog', $username = '', $email = '' ) { 
    354     $hostname = str_replace( "www.", "", $_SERVER[ 'HTTP_HOST' ] ); 
    355     print "  
    356         <form method='post' action='index.php'>  
    357         <input type='hidden' name='action' value='step3'> 
    358         <p>To finish setting up your blog, please fill in the following form and click <q>Submit</q>.</p> 
    359         <input name='submit' type='submit' value='Submit' />  
    360         </form>  
    361         <br /> 
    362         You will be sent an email with your password and login links and details."; 
    363345} 
    364346 
     
    421403} 
    422404 
     405function nowww() { 
     406        $nowww = str_replace( 'www.', '', $_POST[ 'basedomain' ] ); 
     407        ?> 
     408        <h1>No-www</h1> 
     409        <p>WordPress MU strips the string "www" from the URLs of sites using this software. It is still possible to visit your site using the "www" prefix with an address like <em><?php echo $_POST[ 'basedomain' ] ?></em> but any links will not have the "www" prefix. They will instead point at <?php echo $nowww ?>.</p> 
     410        <p>The preferred method of hosting blogs is without the "www" prefix as it's more compact and simple.</p><p>You can still use "<?php echo $_POST[ 'basedomain' ] ?>" and URLs like "www.blog1.<?php echo $nowww; ?>" to address your site and blogs after installation but internal links will use the <?php echo $nowww ?> format.</p> 
     411        <p><a target='_blank' href="http://no-www.org/">www. is depreciated</a> has a lot more information on why 'www.' isn't needed any more.</p> 
     412        <p><form method='POST'> 
     413        <input type='hidden' name='dbname' value='<?php echo $_POST[ 'dbname' ]; ?>'> 
     414        <input type='hidden' name='uname' value='<?php echo $_POST[ 'uname' ]; ?>'> 
     415        <input type='hidden' name='pwd' value='<?php echo $_POST[ 'pwd' ]; ?>'> 
     416        <input type='hidden' name='dbhost' value='<?php echo $_POST[ 'dbhost' ]; ?>'> 
     417        <input type='hidden' name='vhost' value='<?php echo $_POST[ 'vhost' ]; ?>'> 
     418        <input type='hidden' name='weblog_title' value='<?php echo $_POST[ 'weblog_title' ]; ?>'> 
     419        <input type='hidden' name='email' value='<?php echo $_POST[ 'email' ]; ?>'> 
     420        <input type='hidden' name='action' value='step2'> 
     421        <input type='hidden' name='basedomain' value='<?echo $nowww ?>'> 
     422        <input type='submit' value='Continue'> 
     423        </form></p> 
     424        <?php 
     425} 
     426 
    423427switch( $_POST[ 'action' ] ) { 
    424428        case "step2": 
     429                if( substr( $_POST[ 'basedomain' ], 0, 4 ) == 'www.' ) { 
     430                        printheader(); 
     431                        nowww(); 
     432                        continue; 
     433                } 
    425434                // get blog username 
    426435                // create wp-config.php  
     
    429438                include_once('./wp-config.php'); 
    430439                include_once('./wp-admin/upgrade-functions.php'); 
     440                // normalise hostname - no www. 
     441                $_SERVER[ 'HTTP_HOST' ] = str_replace( 'www.', '', $_SERVER[ 'HTTP_HOST' ] ); 
    431442                make_db_current_silent(); 
    432443                populate_options(); 
  • trunk/wpmu-settings.php

    r886 r912  
    2424$path = preg_replace( '|(/[a-z0-9-]+?/).*|', '$1', $path ); 
    2525 
     26function wpmu_current_site() { 
     27        global $wpdb, $current_site, $domain, $path, $sites; 
     28        $path = substr( $_SERVER[ 'REQUEST_URI' ], 0, 1 + strpos( $_SERVER[ 'REQUEST_URI' ], '/', 1 ) ); 
     29        if( constant( 'VHOST' ) == 'yes' ) { 
     30                $current_site = $wpdb->get_row( "SELECT * FROM $wpdb->site WHERE domain = '$domain' AND path='$path'" ); 
     31                if( $current_site != null ) 
     32                        return $current_site; 
     33                $current_site = $wpdb->get_row( "SELECT * FROM $wpdb->site WHERE domain = '$domain' AND path='/'" ); 
     34                if( $current_site != null ) { 
     35                        $path = '/'; 
     36                        return $current_site; 
     37                } 
     38                $sitedomain = substr( $domain, 1 + strpos( $domain, '.' ) ); 
     39                $current_site = $wpdb->get_row( "SELECT * FROM $wpdb->site WHERE domain = '$sitedomain' AND path='$path'" ); 
     40                if( $current_site != null ) 
     41                        return $current_site; 
     42                $current_site = $wpdb->get_row( "SELECT * FROM $wpdb->site WHERE domain = '$sitedomain' AND path='/'" ); 
     43                if( $current_site == null && defined( "WP_INSTALLING" ) == false ) { 
     44                        if( count( $sites ) == 1 ) { 
     45                                $current_site = $sites[0]; 
     46                                die( "That blog does not exist. Please try <a href='http://{$current_site->domain}{$current_site->path}'>http://{$current_site->domain}{$current_site->path}</a>" ); 
     47                        } else { 
     48                                die( "No WPMU site defined on this host. If you are the owner of this site, please check <a href='http://trac.mu.wordpress.org/wiki/DebuggingWpmu'>Debugging WPMU</a> for further assistance." ); 
     49                        } 
     50                } else { 
     51                        $path = '/'; 
     52                } 
     53        } else { 
     54                $current_site = $wpdb->get_row( "SELECT * FROM $wpdb->site WHERE domain = '$domain' AND path='$path'" ); 
     55                if( $current_site != null ) 
     56                        return $current_site; 
     57                $current_site = $wpdb->get_row( "SELECT * FROM $wpdb->site WHERE domain = '$domain' AND path='/'" ); 
     58                if( $current_site == null && defined( "WP_INSTALLING" ) == false ) { 
     59                        if( count( $sites ) == 1 ) { 
     60                                $current_site = $sites[0]; 
     61                                die( "That blog does not exist. Please try <a href='http://{$current_site->domain}{$current_site->path}'>http://{$current_site->domain}{$current_site->path}</a>" ); 
     62                        } else { 
     63                                die( "No WPMU site defined on this host. If you are the owner of this site, please check <a href='http://trac.mu.wordpress.org/wiki/DebuggingWpmu'>Debugging WPMU</a> for further assistance." ); 
     64                        } 
     65                } else { 
     66                        $path = '/'; 
     67                } 
     68        } 
     69        return $current_site; 
     70} 
     71 
    2672$wpdb->hide_errors(); 
    2773$sites = $wpdb->get_results( "SELECT * FROM $wpdb->site" ); // usually only one site 
     
    2975        $current_site = $sites[0]; 
    3076        $path = $current_site->path; 
    31 
    32  
    33 if( isset( $current_site ) == false ) { 
    34         $path = substr( $_SERVER[ 'REQUEST_URI' ], 0, 1 + strpos( $_SERVER[ 'REQUEST_URI' ], '/', 1 ) ); 
    35         if( constant( 'VHOST' ) == 'yes' ) { 
    36                 $current_site = $wpdb->get_row( "SELECT * FROM $wpdb->site WHERE domain = '$domain' AND path='$path'" ); 
    37                 if( $current_site == null ) { 
    38                         $current_site = $wpdb->get_row( "SELECT * FROM $wpdb->site WHERE domain = '$domain' AND path='/'" ); 
    39                         if( $current_site == null ) { 
    40                                 $sitedomain = substr( $domain, 1 + strpos( $domain, '.' ) ); 
    41                                 $current_site = $wpdb->get_row( "SELECT * FROM $wpdb->site WHERE domain = '$sitedomain' AND path='$path'" ); 
    42                                 if( $current_site == null ) { 
    43                                         $path = '/'; 
    44                                         $current_site = $wpdb->get_row( "SELECT * FROM $wpdb->site WHERE domain = '$sitedomain' AND path='$path'" ); 
    45                                         if( $current_site == null && defined( "WP_INSTALLING" ) == false ) { 
    46                                                 if( count( $sites ) == 1 ) { 
    47                                                         $current_site = $sites[0]; 
    48                                                         die( "That blog does not exist. Please try <a href='http://{$current_site->domain}{$current_site->path}'>http://{$current_site->domain}{$current_site->path}</a>" ); 
    49                                                 } else { 
    50                                                         die( "No WPMU site defined on this host. If you are the owner of this site, please check <a href='http://trac.mu.wordpress.org/wiki/DebuggingWpmu'>Debugging WPMU</a> for further assistance." ); 
    51                                                 } 
    52                                         } 
    53                                 } 
    54                         } else { 
    55                                 $path = '/'; 
    56                         } 
    57                 } 
    58         } else { 
    59                 $current_site = $wpdb->get_row( "SELECT * FROM $wpdb->site WHERE domain = '$domain' AND path='$path'" ); 
    60                 if( $current_site == null ) { 
    61                         $path = '/'; 
    62                         $current_site = $wpdb->get_row( "SELECT * FROM $wpdb->site WHERE domain = '$domain' AND path='$path'" ); 
    63                         if( $current_site == null && defined( "WP_INSTALLING" ) == false ) { 
    64                                 $sites = $wpdb->get_results( "SELECT * FROM $wpdb->site" ); 
    65                                 if( count( $sites ) == 1 ) { 
    66                                         $current_site = $sites[0]; 
    67                                         die( "That blog does not exist. Please try <a href='http://{$current_site->domain}{$current_site->path}'>http://{$current_site->domain}{$current_site->path}</a>" ); 
    68                                 } else { 
    69                                         die( "No WPMU site defined on this host. If you are the owner of this site, please check <a href='http://trac.mu.wordpress.org/wiki/DebuggingWpmu'>Debugging WPMU</a> for further assistance." ); 
    70                                 } 
    71                         } 
    72                 } 
    73         } 
     77} else { 
     78        $current_site = wpmu_current_site(); 
    7479} 
    7580