Codeigniter, domain for a specific area of ​​the site

I am not a very experienced programmer, and I use CodeIgniter for the second time.

Suppose I have www.domain1.com. Therefore, I will have, say, 3 controllers / area 1, / 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 that the client wants a certain area of ​​the Internet, say, area2, working as a microsite, in his own domain, so he wants to access area2 using www.domain2.com.

I do not know how to do this with CodeIgniter. Suppose he registered the site www.domain2.com and established that he points to the same DNS, server, etc. How can I get CodeIgnitor to execute controller2 scope when accessing the www.domain2.com URL?

Perhaps a change to $config['base-url'] ? Routing .htaccess ? Please, if you have decided this, you should take into account code usage examples.

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

I have one normal installation of CodeIgniter (external host, I can not access httpd.conf ). It is located on the same machine, and the root of the site should be contacted at www.domain1.com

The entire domain is outside the registered domain. So, I have a home controller that shows me the main page. Suppose the site has 3 areas / area 1, / area2 / area3, with the corresponding controllers displaying these areas.

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

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

+6
php codeigniter .htaccess routing
source share
4 answers

After much searching, I found a solution that seems to work, it is very easy to be honest:

Edit routes.php :

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

No need to rewrite the mod.

+7
source share

Here's a useful link .... http://www.askaboutphp.com/88/codeigniter-setting-up-multiple-sites-on-one-install.html I never did it myself, but it seems like a way to do without installation of two ci. Good luck.

0
source share

you definitely need to go mod_rewrite

0
source share

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

How about using iframe? You can create a domain2.com homepage with a full page iframe that will receive content from the domain1.com / area2.

-one
source share

All Articles