将用户路由到 cakephp 中的 webroot 子文件夹

Routing users to webroot subfolder in cakephp

我希望网站的 / 转到 webroot 中的子文件夹,例如 /app/webroot/frontend/ 和所有 /admin 到标准控制器和 cakephp 的操作。

原因是,我有一个标准的 html 页面作为前端,它使用 ajax 从位于根目录中的 cakephp 获取数据。我不想使用重定向,这样当用户访问该站点时,他们将被重定向到 /app/webroot/frontend(在 URL 中看到这一点)。现在可以通过 /

访问管理员

或者将整个 cakephp 应用程序移动到子文件夹 admin 并将站点 运行 放在根 / 中是否明智?

我认为你不能直接从路由配置路由,因为这是为与 MVC 一起工作而设计的。

要使用清晰的 MVC 代码做到这一点,请按照以下步骤操作。

使用

在 /Controller/MainController 创建 MainController
<?php
class MainController extends AppController {
    public function index(){
        $this->redirect('/frontend/index.html');
    }
}
?>

更改/Config/route.php,找到默认路由规则并替换为:

Router::connect('/', array('controller' => 'main', 'action' => 'index'));

那么,尽情享受吧!