Recently, one of my tasks was to create a Blog and a Knowledge Base and use similar credentials and login-flows for both of their Admin Consoles. Without a doubt, WordPress Multisite is the perfect choice for this since you don’t have to manage your Auth/Settings/Dashboard in multiple places.
Note: Creating WordPress multisites is out of the scope of this article. For more info, check out this link.
When you set up a WordPress Multisite install, you create one root site and then all other multisites are created as subfolders (children). For example, you may end up with something like:
As you can see, this is not ideal, you would ideally want something like this, i.e. each multisite at the same level as the root site (blog):
It turns out – you can easily do this in 3 steps:
Step 1: Create a root level .htaccess
We need to intercept all request to multisites and then rewrite them to their original URLs.
Please note that this is NOT a redirect, but a rewrite. There’s a difference.
Moving along – create an .htaccess file in the root. If you’re using something like XAMPP, create it in the htdocs folder:
Step 2: Update the Database
Just rewriting in the .htaccess is not going to cut it for us. There are some entries in the Database that we need to change:
Step 3: Handle cookies/sessions
Now, we need to handle cookies/sessions since our URLs have changed. Paste the following lines in the wp-config.php file below the multisite lines:
And we’re done! Visit your new multisite URL: http://localhost/knowledgebase and you should be good to go!
Note: For adding more multisites, add a necessary rule in Step 1 and update the necessary tables in Step 2.