CodeIgniter Forums
Handling multiple sites - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Handling multiple sites (/showthread.php?tid=12722)



Handling multiple sites - El Forum - 10-29-2008

[eluser]dijon[/eluser]
Hi,

I have been playing around with getting a better experience from my hosting service. I host 3 sites from the same web root, and from my original look at it (with 1.6.3) had got CI set up with a different controller sudirectory for each site.

Having looked at it again, an unhappy with the system, so I came up with the following structure:

Code:
/path/to/root/ci_system              // CodeIgniter 1.7.0 system folder
    /path/to/root/ci_applications/site1  // default site if nothing else found
    /path/to/root/ci_applications/site2
    /path/to/root/ci_applications/site3  
    /path/to/root/public_html/index.php

In index.php, I've made the following amendments:

Code:
$system_folder = "/path/to/root/ci_system";

and

Code:
$application_folder = "/path/to/root/ci_applications/";

    switch ( $_SERVER['HTTP_HOST'] )
    {
        case "www.site2.com":
        case "site2.com":
            $application_folder .= "site2";
            break;
        case "www.site3.com":
        case "site3.com":
            $application_folder .= "site3";
            break;
        default:
            $application_folder .= "site1";
    }

It does seem to be working as I'd expect, however I was wondering whether (mainly because I'm second guessing myself) if anyone would advise a different approach, or if this seems sensible?

Thanks,

Dan

(p.s. apologies if this topic is posted more than once, I'm getting errors trying to post!)


Handling multiple sites - El Forum - 10-29-2008

[eluser]BorisK[/eluser]
For tweaks like this I prefer to work on the web server level. Apache mod_rewrite module provides means to rewrite apps location to any location on your local or remote server.

Code:
RewriteCond %{HTTP_HOST} \.*site2\.com$
RewriteRule (.*) /path/to/your/app/

You may use this method to further optimize your server. For example, you may use one web server (like Apache) for serving CI apps and another one (like nginx or lighttpd) to serve static content. You start nginx/lighttpd on another port and route all requests for static files to that port.


Handling multiple sites - El Forum - 10-30-2008

[eluser]dijon[/eluser]
Hi there,

First off, thanks for that. I'm still struggling to see how this would improve things, though. As my application folders are outside the document root for Apache, the only part of Codeigniter that's web accessible is the index.php file.

I can see a potential benefit in:

RewriteCond %{HTTP_HOST} \.*site2\.com$
RewriteRule (.*) index_site2.php (where application folder is set to /path/to/root/ci_applications/site2)

but am I missing something (quite likely!!) ??

Thanks,

Dan


Handling multiple sites - El Forum - 10-31-2008

[eluser]Jay Logan[/eluser]
I am looking for a similar solution. But preferably something dynamic. IE: ability to add new sites without hard coding anything.