x
 
Create New Page

Revision: Running Multiple Domains or Subdomains or Subsites

Revision from: 08:46, 4 Jul 2007

Please Note: This is the “classic” method for running multiple sites and sub-domains and is community supported. If you want to run the officially support method for multiple Sites from a single installation of ExpressionEnigne, consider the Multiple Site Manager as it has numerous benefits over this technique.

It is possible to run ExpressionEngine so that content can be accessed from more than one location. This is often desired if you want to put different content on different subdomains or simply otherwise want to access your content through more than one location.
In order to allow this, you simply need to follow a few steps:

Copy index.php and path.php

You must place a copy of the main site path.php and index.php (the ones from your main directory, not from the system directory) files into the directory from which you wish to access ExpressionEngine.
The directory you specify must be able to have files within it be able to access your main installation system directory. You should ensure you don’t have any “open_basedir” or other restrictions in place which could prevent this.
If you want, you may rename the index.php file as described on the Renaming Main Site File page.

Edit path.php

Once you’ve copied the files, you must open path.php to edit it.

$system_path

First, you must ensure that the $system_path variable is set correctly within the file. The variable should contain a relative path from the current directory (in which the path.php file resides) to your site’s system directory. For instance:

$system_path = "../system/";

Add New Variables

Second, you must add several new variables to the file:

$template_group = "template_group_name";
$template = "template_name";
$site_url = "http://www.example.com/subdirectory/";
$site_index = "index.php";
$site_404 = "template_group_name/template_name";

The variables are:

$template_group The name of the Template Group you want to be shown by default.
$template The name of the Template that you want to be shown by default.
$site_url The full URL to the current directory in which this path.php file resides.
$site_index This is an optional variable that will let you indicate the name of the index file if you change the name of index.php to something else.
$site_404 This is an optional variable that will allow you to set a specific Template to display as a 404 page for your subsite. This will override the general site setting for this subsite.

Optional Variables

You may specify a PHP array containing “global variables” that will be available only to Templates accessed through that path.php file.

$global_vars = array(); // This array must be associative

For instance, let’s say you want to define a weblog name and a Template Group name. You could use this:
$global_vars = array(
"my_weblog" => "news",
"my_template_group" => "display"
); // Last entry must not include the comma at the end

Within your Templates, you would then be able to use the {my_weblog} and {my_template_group} variables.

Successful index.php hiding

This is a common practice, if not an official one; it is used also on the Ellis Labs sites.  The result is not seeing ‘index.php’ anywhere in your urls.

For basic hiding, the rules below appear to be the best of several choices.  You simply use the rules in a file named .htaccess, which you place in the root folder of your site.  This is your folder with path.php as well as index.php in it.

The trick to make index.php hiding work with subdomains is to also place an identical .htaccess file in your subdomain root folder(s).  That’s the folder you just created above for the new copies of index.php and (modified) path.php.

Having the rules in both places is necessary, and then your new subdomain will work smoothly.

Here’s what you put in the .htaccess files.  If you already have .htaccess files for another purpose, you would add these codes to what you already have in them.

# rewrite rules
RewriteEngine On

# ditch index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond
%{REQUEST_FILENAME} !-d
RewriteRule
^(.*)$ index.php/$1 [L]

If you already prefer another index.php removal method on your main site, you can try replicating that into your new site’s .htaccess instead.

...

 

Category:Tricks

Categories: