blog/ subsite
-
I’ve googled and followed a lot of instructions but have not been able to figure out how to get my multisite install (with subdirectories) to have sites such as the following:
main site: primary-domain/ <– not viewable by public
subsite1: another-domain/path
subsite2 : yet-another-domain/blog
subsite3: primary-domain/developmentpathObviously main site and subsite1 and subsite3 work, but subsite2 redirects to main site. I’ve followed instructions to remove ‘blog’ as a reserved name for subdirectories. primary-domain/blog gets a 404 page.
I’ve removed ‘blog’ from the slug for main site. I’ve removed ‘blog’ from the rewrite rules. I’ve tried various rewrites and reverse proxy, which I’m not sure I implemented correctly, but the logs indicate that
“GET /blog/ HTTP/1.1” 302 –
The .htaccess file in the wordpress root directory is:
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_URI} !^/(phpmyadmin).*$ RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^ - [L] RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L] RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L] RewriteRule . index.php [L] # END WordPress
The code I use to remove the reserve directory and filter the rewrite rules:
if (!class_exists('WPAllowBlog')) { class WPAllowBlog { public function __construct() { add_filter ( 'subdirectory_reserved_names', array( $this, 'allow_blog_directory') ); try { add_filter ( 'rewrite_rules_array', array( $this, 'allow_blog_filter_rewrite') ); } catch (Exception $e) { $this->allow_blog_add_debug_message($e->getMessage()); } }//end __construct public static function allow_blog_activate() { //delete options if they already exist and initialize them if (get_option('allow_blog_directory_debug') != false) { delete_option('allow_blog_directory_debug'); } add_option('allow_blog_directory_debug', array(), '', false ); //flush the rewrite rules global $wp_rewrite; $wp_rewrite->flush_rules( false ); }//end allow_blog_activate() public static function allow_blog_deactivate() { $delete_debug = delete_option('allow_blog_directory_debug'); }//end allow_blog_deactivate() function allow_blog_directory($allowed){ $allow_blog_directory_array_keys = array_keys ( $allowed, 'blog'); foreach ($allow_blog_directory_array_keys as $k) { unset($allowed[$k]); } return $allowed; } //END allow_blog_directory function function allow_blog_filter_rewrite($rules) { $this->allow_blog_add_debug_message('rules: <br /><pre>' . print_r($rules, TRUE) . '</pre>'); if (empty($rules)) { throw new Exception ('$rules are empty'); } foreach ( $rules as $k => $value ) { if (strpos($value, 'blog')) { unset($rules[$k]); } } //$rules = preg_replace( '/^blog\//', '', $rules); foreach ($rules as $value) { if (strpos($value, 'blog')) { throw new Exception ('filtered rules contain "blog"'); } } self::allow_blog_add_debug_message ('filtered rules: <br /><pre>' . print_r($rules, TRUE) . '</pre>'); return $rules; } private static function allow_blog_add_debug_message($message) { $debug = get_option ('allow_blog_directory_debug' ); $debug[] = $message; update_option('allow_blog_directory_debug', $debug); } public static function allow_blog_display_debug_notice() { $notices = get_option('allow_blog_directory_debug', array() ); foreach ($notices as $lines) { echo '<div class="error"><pre>' . $lines . '</pre></div>'; } } }//END class creation WPAllowBlog }//END check if class_exists('WPAllowBlog') if (class_exists('WPAllowBlog')){ register_activation_hook(__FILE__, array('WPAllowBlog', 'allow_blog_activate')); register_deactivation_hook(__FILE__, array('WPAllowBlog', 'allow_blog_deactivate')); add_action('admin_notices', array('WPAllowBlog', 'allow_blog_display_debug_notice')); add_action('network_admin_notices', array('WPAllowBlog', 'allow_blog_display_debug_notice')); $wpAllowBlog = new WPAllowBlog(); }
- The topic ‘blog/ subsite’ is closed to new replies.