Welcome Guest, Not a member yet? Register   Sign In
Multiple domains using one code base, is it possible?
#1

[eluser]OJ[/eluser]
I have about 5 domains that serve different countries e.g. www.aa.com, www.bb.com, www.cc.com etc each with its own database,config and content unique for that country.

To add anew country, I just replicate on of the domains and change the database settings and update views content.
The challenge comes when I need to add a new feature, I have to go round all these domains to make a change.
Is it possible for me solve this at config level so that when www.aa.com, ww.bb.com etc is clicked, it will point to the same code base(controllers,models etc) but able to point correctly to its own database and specific content.

Any help will be greatly appreciated!
#2

[eluser]CroNiX[/eluser]
Sure, you can just check the value of $_SERVER['HTTP_HOST'] and load the appropriate settings based on the site being accessed.

Additionally you can make use of the ability to set the /application and /system directory locations in index.php, so all of your sites can share the single codebase. You just move these directories elsewhere on the server, outside of webroot, and then define them in the index.php. Further, your index.php could just be a symlink to a single index.php file located elsewhere, so you only have 1 index.php to maintain as well. It would be up to your application logic to load what needs to be loaded for the requested domain. I have almost 200 websites running off of a similar setup with a single codebase, and each site is totally different.
#3

[eluser]OJ[/eluser]
Hello CroNix,
I am glad that you have done this.I need a little bit more help with any code snippets that you can share.
$_SERVER[‘HTTP_HOST’]
I wasn't sure if what I need to switch is config file or the app folders

Since each domain has its own config that points to its DB, I was thinking of switching config file by doing something like this in the config
switch ( $_SERVER[‘HTTP_HOST’] )
{
case "abc.com":
include_once("abc_config.php");

break;

case "xyz.com":
include_once("xyz_config.php");


break;

default:
die ("Something has gone really wrong.Send us an email");
}

I did try the above and the correct config file is called but the database associated to the config is not being called.
I was hoping to drive the uniqueness of the view from the config files. Could you please share a code snippet on how to put this all together




Theme © iAndrew 2016 - Forum software by © MyBB