CodeIgniter Forums
Subdomain(s) and S_SERVER['HTTP_HOST'] - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Installation & Setup (https://forum.codeigniter.com/forumdisplay.php?fid=9)
+--- Thread: Subdomain(s) and S_SERVER['HTTP_HOST'] (/showthread.php?tid=69612)



Subdomain(s) and S_SERVER['HTTP_HOST'] - DimCI - 12-22-2017

Hi guys,

Can you tell me if the following is a good practice or not:

I want to create a few subdomains so that they use the same application directory as the main site.

Is this correct to setup Sconfig['base_url'] = S_SERVER['HTTP_HOST'] ?

Thank you


RE: Subdomain(s) and S_SERVER['HTTP_HOST'] - jreklund - 12-22-2017

No, you should do it like this:
https://www.codeigniter.com/userguide3/installation/upgrade_303.html


RE: Subdomain(s) and S_SERVER['HTTP_HOST'] - DimCI - 12-22-2017

(12-22-2017, 08:49 AM)jreklund Wrote: No, you should do it like this:
https://www.codeigniter.com/userguide3/installation/upgrade_303.html

Thank you! Wink


RE: Subdomain(s) and S_SERVER['HTTP_HOST'] - XtreemDeveloper - 12-24-2017

You can use this code
$allowed_domains = array('domain1.tld', 'domain2.tld');
$default_domain  = 'domain1.tld';

if (in_array($_SERVER['HTTP_HOST'], $allowed_domains, TRUE))
{
        $domain = $_SERVER['HTTP_HOST'];
}
else
{
        $domain = $default_domain;
}

if ( ! empty($_SERVER['HTTPS']))
{
        $config['base_url'] = 'https://'.$domain;
}
else
{
        $config['base_url'] = 'http://'.$domain;
}