Make WordPress Core


Ignore:
Timestamp:
03/11/2010 10:33:52 PM (15 years ago)
Author:
nacin
Message:

Improve multisite rewrite rules. Construct rules dynamically and skip subdirectory-specific rules for subdomain installs. see #12136

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/network.php

    r13656 r13675  
    2222
    2323/**
    24  * Check for existing network data/tables.
    25  *
    26  * @since 3.0.0
     24 * Check for an existing network.
     25 *
     26 * @since 3.0.0
     27 * @return Whether a network exists.
    2728 */
    2829function network_domain_check() {
     
    3738 *
    3839 * @since 3.0.0
     40 * @return string Base domain.
    3941 */
    4042function get_clean_basedomain() {
    41     global $wpdb;
    42     $existing_domain = network_domain_check();
    43     if ( $existing_domain )
     43    if ( $existing_domain = network_domain_check() )
    4444        return $existing_domain;
    4545    $domain = preg_replace( '|https?://|', '', get_option( 'siteurl' ) );
    46     if ( strpos( $domain, '/' ) )
    47         $domain = substr( $domain, 0, strpos( $domain, '/' ) );
     46    if ( $slash = strpos( $domain, '/' ) )
     47        $domain = substr( $domain, 0, $slash );
    4848    return $domain;
    4949}
     
    281281</li>
    282282<?php
    283 
    284 // @todo custom content dir
     283// Construct an htaccess file.
    285284$htaccess_file = 'RewriteEngine On
    286285RewriteBase ' . $base . '
    287286
    288287# uploaded files
    289 RewriteRule ^(.*/)?files/$ index.php [L]
    290 RewriteCond %{REQUEST_URI} !.*wp-content/plugins.*
    291 RewriteRule ^(.*/)?files/(.*) wp-includes/ms-files.php?file=$2 [L]
    292 
    293 # add a trailing slash to /wp-admin
    294 RewriteCond %{REQUEST_URI} ^.*/wp-admin$
    295 RewriteRule ^(.+)$ $1/ [R=301,L]
    296 
    297 RewriteCond %{REQUEST_FILENAME} -f [OR]
     288RewriteRule ^' . ( $vhost ? '([_0-9a-zA-Z-]+/)?' : '' ) . 'files/(.+) wp-includes/ms-files.php?file=$2 [L]' . "\n";
     289
     290if ( ! $vhost )
     291    $htaccess_file .= "\n# add a trailing slash to /wp-admin\n" . 'RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]' . "\n";
     292
     293$htaccess_file .= "\n" . 'RewriteCond %{REQUEST_FILENAME} -f [OR]
    298294RewriteCond %{REQUEST_FILENAME} -d
    299 RewriteRule . - [L]
    300 RewriteRule  ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
    301 RewriteRule  ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
    302 RewriteRule . index.php [L]';
     295RewriteRule ^ - [L]';
     296
     297// @todo custom content dir.
     298if ( ! $vhost )
     299    $htaccess_file .= "\n" . 'RewriteRule  ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
     300RewriteRule  ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]';
     301
     302$htaccess_file .= "\nRewriteRule . index.php [L]";
     303
    303304?>
    304305            <li><p><?php printf( __( 'Add the following to your <code>.htaccess</code> file in <code>%s</code>, replacing other WordPress rules:' ), ABSPATH ); ?></p>
    305                 <textarea class="code" readonly="readonly" cols="100" rows="18">
     306                <textarea class="code" readonly="readonly" cols="100" rows="<?php echo $vhost ? 10 : 15; ?>">
    306307<?php echo wp_htmledit_pre( $htaccess_file ); ?>
    307308</textarea></li>
Note: See TracChangeset for help on using the changeset viewer.