[eluser]stealthify[/eluser]
Hi all,
First post, but long-time fan of CodeIgniter. While things have been smooth-sailing with CI for my previous adventures, my first question for you guys happens to be a doozy.

The Concept
One CI installation, one database, one application --&gt; routed to from multiple domains --&gt; domain determines the controller to route to (so multiple controllers, multiple languages, multiple views)

I understand that there are probably a few different ways to go about this, but the folder structure I decided upon was:

I figured this was my best bet, since really all of my configs, helpers, models, libraries, etc will remain the same, no matter which domain I have routed to my CI install.

My Goal
After poking around and exploring how the current routing system works, my plan of action was to determine which domain the code is executing under, and then querying a database to gather some preliminary info on which controller to call (ie: the default fallback if it doesn't exist in the database, or if it is found, the appropriate controller in the 'controllers/sites/' directory).

My Progress
The idea sounds simple enough, and I know how to extract the domain and run a query based on this domain. From there, I also know how to run a check to make sure that the controller exists (ex: controllers/sites/domain1/home.php).

My Question
What I'm stuck on is trying to figure out where I need to start in order to tell CI to call my alternate controller as opposed to the default controller. Will something like this require a modification of the system core? Or is it override-able from my 'application/' folder?

Lastly, do any of you see any pitfalls to using this method? Is there a better way to go about this?

[eluser]stealthify[/eluser]
Hi Toopay, thanks for that! I like that idea, especially since it keeps all of the frameworks together (CI, Kohana, etc).

I'll run that direction with it tonight, I saw some other people suggesting this method in other multi-domain/single-system threads that I found when searching.

The part I imagine I'll need the most guidance on is trying to figure out how to share the same application cache, config, core, helpers, hooks, libraries, logs and models across all of the domains. I was hoping that the index.php would have given a spot to define these custom folder paths, but there must be another way.

Any suggestions in this department?

(once again, the only folders that will be dynamic across all of the domains include: controllers, language and views. All others will be shared.)

[eluser]toopay[/eluser]
With above suggestion, each domain is a single independent application, which use same framework resource (in this case, CI). That mean each application has its own resource. If you need, to share common resource (like core, config, helper, libraries etc) in your each application its look like HMVC with one application folder (with modules) is your solution instead create multiple application. Search on forum or wiki 'HMVC' or 'Modular CI' for that. Then you may just need to set a proper htaccess on every domain/sub domain to redirect it properly to each modules.

[eluser]stealthify[/eluser]
Wow, this is genius! I hadn't even considered this approach, and it appears to be working well. I took your advice, and added HMVC to my application, and then reworked the file structure. As it stands now, this is what I'm working with:

I have been struggling throughout the night to figure out the best way to capture the domain that is requesting the public_html directory, and then disguising what they see so that all they see is the following:

you could create multiple domain folders within the public_html folder
in each domain folder you have a index.php and a .htacces file (forward the domain to the folder)
make sure that the directory for the application folder is set correct in the index.php
then you just add a .htaccess file like this

I have a domain, say domain1.com, pointed to the directory with the 'application/' and index.php file in it. I have also, just for now, hardcoded the $config['base_url'] to be 'http://www.domain1.com/'. I will make this dynamic again after I figure this out.

With above regex, it will capture your exist domain (site1.com/foo or www.site1.com/foo) and after validate if the directory is valid(represented with DOCUMENT_ROOT) these should be redirect it into index.php/domain1.com/foo