1

与 Codeigniter 一样,假设我有$route['default_controller'] = "welcome";,如果我请求左侧的 url,我将使用右侧列出的控制器:

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"

这一切都在预料之中。但是当使用子域时,我想让codeigniter在与子域同名的子目录中使用控制器:

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"

这可以通过路线完成吗?如果是这样,您如何根据子域设置路由?

或者有没有更简单的方法来做到这一点?

4

2 回答 2

1

您可以检查 routes.php 文件中的子域,例如:

if (strstr($_SERVER['HTTP_HOST'], 'abc.foo.com')) {
   $route['uri'] = "abc/controller/method";
}
于 2013-01-17T14:31:12.537 回答
0

是的,这是可能的,

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

于 2013-01-17T11:16:44.843 回答