Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter's Subdomain Support
#5

[eluser]moodh[/eluser]
I use a standard installation and get subdomains mapped to various controllers without a problem at all:
Index.php example:
Code:
<?php
// Normal app/system paths

// Host address
$host = $_SERVER['HTTP_HOST'];

// Extract eventual subdomain
$subdomain = substr($host, 0, strrpos(substr($host, 0, strrpos($host, '.')), '.'));

// Define subdomain
if($subdomain !== 'www' && $subdomain !== '') {
    define('SUBDOMAIN', $subdomain);
} else {
    define('SUBDOMAIN', FALSE);
}

// Rest of index.php
?>

Routes.php example:
Code:
<?php
if(SUBDOMAIN === FALSE) {
    $route['default_controller'] = "foo";
} else {
    $route['default_controller'] = "bar";
    $route['what-is-my-subdomain'] = 'this_is_my_sub_domain/' . SUBDOMAIN;
}
?>

Edit: Of course this needs a .htaccess that redirects everything, subdomains or not to the root url without changing it.
Edit2: and you dont need to use the constant SUBDOMAIN, another look at $_SERVER['HTTP_HOST']; still contains the subdomain for usage in your code =)


Messages In This Thread
CodeIgniter's Subdomain Support - by El Forum - 11-06-2009, 11:39 AM
CodeIgniter's Subdomain Support - by El Forum - 11-06-2009, 11:47 AM
CodeIgniter's Subdomain Support - by El Forum - 11-07-2009, 09:07 PM
CodeIgniter's Subdomain Support - by El Forum - 11-08-2009, 05:46 AM
CodeIgniter's Subdomain Support - by El Forum - 11-08-2009, 08:32 AM



Theme © iAndrew 2016 - Forum software by © MyBB