Welcome Guest, Not a member yet? Register   Sign In
pointing multiple domains to same instance of CI
#1

[eluser]niyogi[/eluser]
we need to point multiple domains to the same instance of codeigniter. As the user browses from page to page, they should remain on the same domain. Does anything special need to be done to achieve this?

To make things a little bit more complicated we need each domain to point to a specific controller. How would we do this?

You're help is greatly appreciated!
#2

[eluser]Colin Williams[/eluser]
Assuming Apache:

Code:
NameVirtualHost *:80

<VirtualHost *:80>
    DocumentRoot /path/to/ci/install
    ServerName domain1.com
        ServerAlias domain2.com
    
    <Directory "/path/to/ci/install">
                Options Indexes FollowSymLinks Includes ExecCGI
                AllowOverride All
                Order allow,deny
                Allow from all
    </Directory>
</VirtualHost>

And then in routes:

Code:
$check_host = $_SERVER['SERVER_NAME'];

$route['default_controller'] = "welcome";
if ($check_host == 'domain2.com')
{
   $route['default_controller'] = "other";
}
#3

[eluser]niyogi[/eluser]
This is awesome to see. Thanks so much Colin. I will try this out and see how things go.

Which part keeps you on the domain and not send you to the base_url domain upon navigation to another page? Or am I assuming incorrectly in the first place?
#4

[eluser]Colin Williams[/eluser]
Either set your base_url to "/" or do the same check I did above

Code:
$check_host = $_SERVER['SERVER_NAME'];

$config['base_url'] = "http://domain1.com/";
if ($check_host == 'domain2.com')
{
   $config['base_url'] = "http://domain2.com/";
}
#5

[eluser]niyogi[/eluser]
Colin

Thanks again for this - I was able to use your code examples/suggestion as hints and make this all work.

CI rocks.
#6

[eluser]Iverson[/eluser]
If I'm understanding the question correctly, there's no reason to touch the controllers. If you just need exampleA.com and exampleB.com to be the exact same thing (database included), all you need to do is go inside the config.php and use:

Code:
$host = $_SERVER['SERVER_NAME'];    // resolves to www.exampleA.com OR www.exampleB.com
$config['base_url']    = "http://" . $host . '/';

I use this method currently on a site.




Theme © iAndrew 2016 - Forum software by © MyBB