-
-
Save lusareal/5911d4cf47df3f2c6fe65f1ba8f6c71a to your computer and use it in GitHub Desktop.
Set up WordPress Multi Network
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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