Skip to content

Instantly share code, notes, and snippets.

@wpscholar
Last active March 4, 2019 17:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save wpscholar/f20b1299e4e08f78c33fda5f61ecd17c to your computer and use it in GitHub Desktop.
Save wpscholar/f20b1299e4e08f78c33fda5f61ecd17c to your computer and use it in GitHub Desktop.
Set up WordPress Multi Network
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
#RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^(.+)?/(wp-(content|admin|includes).*) /$2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]
</IfModule>
# END WordPress
<?php
if ( ! defined( 'SUNRISE_LOADED' ) ) {
define( 'SUNRISE_LOADED', 1 );
}
$sites = $wpdb->get_results( "SELECT * FROM {$wpdb->site} ORDER BY CHAR_LENGTH(path) DESC" );
foreach ( $sites as $site ) {
if ( false !== strpos( $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . '/', $site->domain . $site->path ) ) {
$site_id = $site->id;
$current_site = $site;
$wpdb->siteid = $site->id;
break;
}
}
$blogs = $wpdb->get_results( "SELECT * FROM {$wpdb->blogs} WHERE site_id = {$site_id} ORDER BY CHAR_LENGTH(path) DESC" );
foreach ( $blogs as $blog ) {
if ( false !== strpos( str_replace( $site->domain, '', $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . '/' ), $blog->path ) ) {
$blog_id = $blog->blog_id;
$current_blog = $blog;
$wpdb->blogid = $blog->id;
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment