Last active
December 7, 2022 22:18
-
-
Save colegeissinger/b7d98e53997812e7f82113721e9f0a74 to your computer and use it in GitHub Desktop.
How to enable multilevel directory WordPress multisite install. You Multisite should be configured with subdirectories rather than subdomains as the default.
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
# This should be used over the server.conf if you are running on Apache and need .htaccess rewrites. Ref this documentation for more details https://wordpress.org/support/article/htaccess/#wordpress-3-5-and-up | |
RewriteRule ^(/[_0-9A-Za-z-]+\/?)+(wp-(content|admin|includes).*) $2 [L] | |
RewriteRule ^(/[_0-9A-Za-z-]+\/?)+(.*\.php)$ $2 [L] |
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
# Below is an update to your NGINX rules. If you need .htaccess rewrites, use that file example in this gist. Ref this docuemntation for more details https://wordpress.org/support/article/nginx/#wordpress-multisite-subdirectory-rules | |
if (!-e $request_filename) { | |
rewrite /wp-admin$ $scheme://$host$uri/ permanent; | |
rewrite ^(/[_0-9A-Za-z-]+\/?)+(/wp-.*) $2 last; | |
rewrite ^(/[_0-9A-Za-z-]+\/?)+(/.*\.php) $2 last; | |
} |
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 | |
// Add the sunrise.php file to the root of your wp-content directory. | |
/** | |
* Ensure WordPres will check deeper levels of directories. By default $num_segments is null, | |
* This function will filter that to ensure we can account for deeper nested paths. | |
* | |
* E.g. if a site is 5 directories deep www.mysite.com/some/url/that/goes/deep/ you can set the number to 5. | |
* This also applies to subdomained sites. subdomain.mysite.com/some/url/that/goes/deep/ | |
* | |
* @param int|null $num_segments Variable isn't returned or modified directly. | |
* @return int | |
*/ | |
function cg_site_by_path_segments_count( $num_segments ): int { | |
return 5; | |
} | |
add_filter( 'site_by_path_segments_count', 'cg_site_by_path_segments_count', 99 ); |
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 | |
... | |
// Add the below code to your wp-config.php, ideally after all the multisite configurations and before the "That's all, stop editing!". | |
define( 'SUNRISE', true ); | |
define( 'COOKIE_DOMAIN', $_SERVER['HTTP_HOST'] ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
NOTE: I included server rewrites for both Nginx and Apache. Use which ever configuration your server is using. Also note, the .htaccess hasn't been tested yet, so use with caution as it may need some additional tweaks.