Pergunta

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?

Foi útil?

Solução

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

if (strstr($_SERVER['HTTP_HOST'], 'abc.foo.com')) {
   $route['uri'] = "abc/controller/method";
}

Outras dicas

Yes it's possible,

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

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top