2017-06-01 101 views
0

我的网站是使用CakePHP和主页网址被重定向,看起来像这样CakePHP的主页URL重定向

domain.com/pages/home 

我想防止domain.com重定向负载索引文件我无法弄清楚如何在不加载索引重定向。

这就是我现在所拥有的。

if(!$this->Auth->loggedIn()){ 
     return $this->redirect('/pages/home'); 
    } 
+0

你说的是路由? https://book.cakephp.org/3.0/en/development/routing.html –

+0

我尝试过路由,但是我无法使它工作。如果(!$ this-> Auth-1)在路由器上连接('/',array('controller'=>'pages','action'=>'home')) > loggedIn()){ \t \t \t $ this-> home(); \t \t}' – DN0300

回答

2

如果您有这行代码(如果没有添加它),请检查routes.php文件。

Router::connect('/', array('controller' => 'pages', 'action' => 'home')); 

,这在控制器

if(!$this->Auth->loggedIn()){ 

    $this->redirect('/'); 
    //or 
    //$this->redirect(array('controller' => 'pages', 'action' => 'home')); 

} 
+0

我试过了,吐出google chrome错误“This Page Is Work” – DN0300

+0

在哪个控制器函数中添加了重定向代码? –

+0

PagesController,SignedIn函数 – DN0300