Building a Sub-Folder Site in ExpressionEngine MSM

For many, using ExpressionEngine’s content management system stops at a single site: one and done, rinse and repeat. But, if you’re one of the EE community members that has used, or will be using, the Multiple Site Manager (MSM), this article will discuss how to setup a new site in a sub-folder.

Setting the Stage

When first tackling the MSM install, you'll likely begin with the core documentation and work from there. Because EllisLab typically has terrific documentation, getting started is a breeze. Steps 1-3 are simple enough and you'll surely be at Step 4 in no time.

I should note that the following method was successful when developing in a (mt) Media Temple DV server environment. This article is by no means a a guaranteed solution for all hosting environments. Please review this documentation carefully and always backup your database before performing any major task to your EE site!

For my recent MSM expansion, I was going to be using sub-folders (e.g. /gb/, /de/, and so on) instead of sub-domains to delineate information from site to site based on international regions for linguistic purposes. The task was to duplicate content over to a new site, keeping all content the same in preparation for region-based adjustments, translations, and more.

Step 4

At Step 4 of the process, the documentation simply states: Set up public access via a sub-folder, sub-domain, or domain. Because the next step links to "Setup domains and sub-domains" I came to a bit of a halt in the development process. Where do I create a sub-folder? In the root? Within my /system/ folder?

I didn't see any directive based on sub-folders. The EE community helped me figure a few things out, and after researching a few similar-minded posts, I finally stumbled upon a solution; now clearly outlined below.

Sub-Folder Setup Process

Again, be sure you read the official EE MSM documentation prior to adjusting your new MSM site. This process will pick up at Step 4, just after you will have made a few configuration adjustments.

1. Create the sub-folder /gb/ for the new site (use your folder name, of course) along side your /system/ folder. Note that your /system/ folder may be something else, such as /admin/ if you chose to change it during the initial EE install. The hierarchy of the root folder would be:

.htaccess
admin
gb
(...)

2. Within your sub-folder, copy the index.php and path.php files from the root (not from inside the /system/ folder). Also create a blank .htaccess file that you will work with later. Thus, the /gb/ folder would contain:

.htaccess
index.php
path.php

3. Modify the rules of the path.php file according the Domains and Sub-domains setup in the MSM documentation. In this case, change the $system_path, add the $site_name variable (created during MSM new site setup) and adjust the $site_url as so:

<?php

// ------------------------------------------------------
// DO NOT ALTER THIS FILE UNLESS YOU HAVE A REASON TO

// ------------------------------------------------------
// Path to the directory containing your backend files

$system_path = "../admin/";

// ------------------------------------------------------
// MANUALLY CONFIGURABLE VARIABLES
// See user guide for more information
// ------------------------------------------------------

$site_name = 'mysite_gb';
$template_group = "";
$template = "";
$site_url = "http://mysite.com/gb";
$site_index = "";
$site_404 = "";
$global_vars = array(); // This array must be associative

?>

4. Double check that the URL is correct within the Control Panel. Toggle to the General Configuration and make sure the URL to the root directory to your site is set properly:

http://mysite.com/gb

The website I was working with used the LG .htaccess Generator extension for creating the .htaccess file automatically. Therefore, I needed to be sure to edit it accordingly so that it reflected the new sub-folder conditions now in place. After duplicating over to a new site, extension settings will be as new, so it's important to copy and paste identical data from the parent site to give yourself a foundation to work with.

5. Open up the LG extension settings (be sure you're not in the default site). Modify the server directory path:

/var/www/vhosts/mysite.com/httpdocs/gb/

6. Modify the .htaccess file while still in the LG extension settings screen by adding in the /gb/ sub-folder path information. In this case, at the rewrite base, and twice below at the URI and RewriteRule lines:

RewriteBase /gb/ # Remove index.php
# Uses the "include method"
# http://expressionengine.com/wiki/Remove_index.php_From_URLs/#Include_List_Method
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5})$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} ^/gb/({ee:template_groups}|members|P[0-9]{2,8}) [NC]
RewriteRule ^(.*)$ /gb/index.php?/$1 [L]

Testing the URL Segment

At this point you should be able to access http://mysite.com/gb without issue. Also, by adjusting the .htaccess file accordingly, you should be able to click anywhere in the site and retain the http://mysite.com/gb/about structure, with the proper template and entries showing up.

Potential Issues

I ran into quite a few small glitches along the way, which ultimately forced me to double check the index.php and path.php settings, making sure my CP settings were correct for the new MSM site, and so on and so forth. Like most development and setup issues, if you encounter a problem, it's best to start taking things away one at a time so as to not make multiple changes a once, and blindly hope for something to begin to work.

Keep in mind that the ExpressionEngine crew doesn't officially support modification of the .htaccess file, so be sure you have a sense of what you're getting into before beginning any modification. Read a few posts and all the documentation you can get your hands on.

Being my first MSM outing, it took a little practice to realize that the system likes to cruise back to the parent site at times, so be sure you're within the CP of the site with which you want to edit, and not the default site. An easy way to do this is to set the title of each CP with the LG Add Sitename extension.

Community

If all else fails, open up a thread on the ExpressionEngine Forum and engage in dialogue with fellow EE developers. You may find a better solution for your situation, or even uncover a better approach to your particular issue. It's nice to know you always have a community to help you through the best and worst times with a powerful foreign language.

Sharing is caring.

Preferred short URL → http://DesignLitm.us/u/20