1

As is usual with Codeigniter, assuming I have $route['default_controller'] = "welcome";, if I request the url on the left, I am using the controllers listed on the right:

www.foo.com/         =>  applications/controllers/welcome.php with method "index"
www.foo.com/bar      =>  applications/controllers/bar.php with method "index"
www.foo.com/bar/baz  =>  applications/controllers/bar.php with method "baz"

This is all as expected. But when a subdomain is used, I would like to have codeigniter use controllers in a subdirectory with the same name as the subdomain:

abc.foo.com/         =>  app/controllers/abc/welcome.php with method "index"
abc.foo.com/baz      =>  app/controllers/abc/baz.php with method "index"
abc.foo.com/baz/qux  =>  app/controllers/abc/baz.php with method "qux"

Can this be done with routes? If so, how do you set routes based on subdomain?

Or is there a simpler way to do this?

pbarney
  • 2,529
  • 4
  • 35
  • 49

2 Answers2

1

You can check for subdomains in routes.php file like:

if (strstr($_SERVER['HTTP_HOST'], 'abc.foo.com')) {
   $route['uri'] = "abc/controller/method";
}
CM.
  • 670
  • 1
  • 6
  • 25
0

Yes it's possible,

$route['the/path'] = "folder/controller/method";

Massimiliano Marini
  • 499
  • 1
  • 6
  • 16