views:

87

answers:

4

Hi, I'm not a very experienced programmer, and am using CodeIgniter for second time.

Suppose I have www.domain1.com. So I will have, say 3 controllers /area1, /area2, /area3. Users can access them as www.domain1.com/area1 etc. if I set the base URL as www.domain1.com. But my problem is, the client wants a certain area of the web, say area2, working as a microsite, in its own domain, so he wants to access area2 with www.domain2.com.

I don't know how to get this working with CodeIgniter. Suppose he registers www.domain2.com and set it pointing to the same DNS, server etc. How can I get CodeIgnitor to execute the controller area2 when the URL www.domain2.com is accessed?

Maybe changing $config['base-url']? Routing? .htaccess? Please, if you have solved this, examples of code involved would be greatly appreciated.

Edit: I will put example of the site I want to get.

I have one normal installation of CodeIgniter (external host, I can't access httpd.conf) It is on one machine, and the root of the site should be accessed by www.domain1.com

All domain are outside registered to. So I have the home controller, which shows me the main page view. And suppose the site have 3 areas /area1, /area2 /area3, with their correspondent controllers, showing these areas views.

My client want to emphasize one of the areas, the one that controller /area2 shows, and he want use a different domain for that area, www.domain2.com

What can I do so that when the user browse to www.domain2.com, CI redirects them to www.domain1.com/area2? Could I, for example, modify $config['base_url'] according the received URL, or is that impossible? Do I need to modify the .htaccess file?

A: 

Here's a helpful link.... http://www.askaboutphp.com/88/codeigniter-setting-up-multiple-sites-on-one-install.html Never actually done this myself, but this seems to be the way to go about it without having two ci installs. Good luck.

anthonyjack
Cheked the site ...
Luis Javier Garrido
This is not really my case, so i dont want to have diffreent aplications like he does. I just want to access a part of my only aplication (it is a part of the whole web anyway) with a different domain. Check example on my edit.
Luis Javier Garrido
A: 

Hi, the first solution that comes to my mind is to use Apache mod_rewrite, but as far as I know that would work only for internal redirects (i.e. resources residing on the same server/domain).

What about using an iframe? You could set up domain2.com home page with a full-page iframe that takes it's content from domain1.com/area2.

mjsarfatti
I will try studing mod_rewrite posibilities then. The iframe idea is a good pont too, will try that too.
Luis Javier Garrido
A: 

you definitely need to go the mod_rewrite way

Herr Kaleun
I will try studing mod_rewrite posibilities then
Luis Javier Garrido
+2  A: 

After a lot of searching, I found a solution that seems to work, very easy to be honest:

Modify routes.php:

if ($_SERVER['HTTP_HOST']=="www.domain2.com") {
    $route['default_controller'] = "area2"; 
}

No need for mod rewrite.

Luis Javier Garrido
I like this one, you also need to make sure domain1.com can't access area2, eg. add: if($_SERVER['HTTP_HOST']=="www.domain1.com"){$route['area2']="diff_controller";}
Mitchell McKenna