Return to Snippet

Revision: 17009
at August 20, 2009 13:33 by brettbergeron


Initial Code
$domain = $_SERVER['HTTP_HOST'];

if(fnmatch('*.*.*', $domain)) {
 $subdomain = explode(".", $_SERVER['HTTP_HOST']);
 $application_folder = ($subdomain[0] == "www") ? "application/live" : "application/".$subdomain[0];
} else {
 $application_folder = "application/live";
}

Initial URL
http://brettbergeron.com

Initial Description
I recently found the need to run multiple CodeIgniter applications inside of a single codebase for development & test purposes. So, I rewrote a few lines of the primary index file (/index.php) to automatically route URLs like subdomain.domain.com to the CodeIgniter application within /system/application/subdomain.

As a catch-all, the snippet will route the "www" subdomain (and requests with no subdomain) to application/live.

This is a nice & tidy way to give your development, test and live versions of a site their own unique subdomains. Works great when passing the URLs to clients for testing & approval.

Initial Title
Call CodeIgniter Application Based on Subdomain

Initial Tags
php, codeigniter

Initial Language
PHP