2014-03-26 55 views
0

我正在使用CakePHP 2.3。我希望將舊頁面重定向到具有HTTP 301狀態的新頁面。現在我的網址看起來像http://www.example.com/profile/johnhttp://www.example.com/profile/john/shopCakePHP 2.3。 - 重定向301不起作用

我想的URL看起來像http://www.example.com/user/johnhttp://www.example.com/user/john/shop分別

我routes.php文件

Router::connect(
    '/profile/:profile_name', 
    array(
     'controller' => 'profile', 
     'action' => 'index', 
    ), 
    array (
     'pass' => array('profile_name') 
    ) 
); 

Router::connect(
    '/profile/:profile_name/shop', 
    array(
     'controller' => 'profile', 
     'action' => 'shop' 
    ), 
    array(
     'pass' => array('profile_name') 
    ) 
); 

我重定向是:

Router::redirect(
    '/user/:profile_name', 
    array(
     'controller' => 'profile', 
     'action' => 'index', 
    ), 
    array (
     'persistent' => true, 
     'status' => 301 
    ) 
); 

    Router::redirect(
    '/user/:profile_name/shop', 
    array(
     'controller' => 'profile', 
     'action' => 'shop', 
    ), 
    array (
     'persistent' => true, 
     'status' => 301 
    ) 
); 

但它不起作用。 404頁面仍然顯示

我是想,因爲它是在教程中,但沒有說明這樣做的工作

+1

心不是你的控制器稱爲'ProfilesController'? – noslone

+0

是的,它應該被稱爲配置文件 - 約定。這可能是問題嗎? – vlcik

+0

這可能是問題所在,你可以通過將''controller'=>'profile''改爲''controller'=>'profiles''來嘗試它。 – noslone

回答

0

我想這是因爲有「」多。

Router::connect('/profile/:profile_name', array('controller' => 'profile','action' => 'index') , array ('pass' => array('profile_name'))); 

Router::connect('/profile/:profile_name/shop', array('controller' => 'profile','action' => 'shop'), array('pass' => array('profile_name'))); 

同樣在這裏:

Router::redirect(
    '/user/:profile_name', 
    array(
     'controller' => 'profile', 
     'action' => 'index' 
    ), 
    array (
     'persistent' => true, 
     'status' => 301 
    ) 
); 

    Router::redirect(
    '/user/:profile_name/shop', 
    array(
     'controller' => 'profile', 
     'action' => 'shop' 
    ), 
    array (
     'persistent' => true, 
     'status' => 301 
    ) 
); 
+0

我不明白,對不起,能否請你解釋一下? – vlcik

+0

好的,在你的'action'=>'index'之後有一個逗號,< - 在這裏,也許我是那個問題,但在這種情況下可能不是這樣:Router :: connect '/ profile /:profile_name/shop',array('controller'=>'profile','action'=>'index',array('pass'=> array('profile_name')))); – CoolLife