Sub Domain and Sub Directory on same wordpress installation

It is very simple to configure wordpress multisite with sub-domain and sub directory. Do as follows.

define('t2vhyu85e1_ALLOW_MULTISITE', true);
define( 'MULTISITE', true );
if($_SERVER['HTTP_HOST']==
'www.newsite.com')
{
define( 'SUBDOMAIN_INSTALL', false );
}
else{
define( 'SUBDOMAIN_INSTALL', true );
}
$base = '/';
define( 'DOMAIN_CURRENT_SITE', 'www.ask4solution.org' );
define( 'PATH_CURRENT_SITE', '/' );
define( 'SITE_ID_CURRENT_SITE', 1 );
define( 'BLOG_ID_CURRENT_SITE', 1 );

Trick is as wordpress loads from HTTP_HOST we can also say to wordpress based on the same.

We need to add combined htaccess rule for the same.


# BEGIN WordPress
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]
RewriteRule ^wp-admin$ wp-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).*) $1 [L]

RewriteRule ^([_0-9a-zA-Z-]+/)?(.*.php)$ $2 [L]
RewriteRule ^(.*.php)$ $1 [L]

RewriteRule . index.php [L]
# END WordPress

 

Categories: Wordpress