Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeigniter, domain to a certain area of the site

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?

like image 420
Luis Javier Garrido Avatar asked Oct 02 '10 08:10

Luis Javier Garrido


1 Answers

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.

like image 70
Luis Javier Garrido Avatar answered Oct 09 '22 15:10

Luis Javier Garrido