【问题标题】:CakePHP 2.3. - redirect 301 not workingCakePHP 2.3。 - 重定向 301 不起作用
【发布时间】:2014-05-05 00:08:33
【问题描述】:

我正在使用 Cakephp 2.3。我想将旧页面重定向到具有 HTTP 301 状态的新页面。现在我的 URL 看起来像 http://www.example.com/profile/john 和 http://www.example.com/profile/john/shop

我希望 URL 分别看起来像 http://www.example.com/user/john 和 http://www.example.com/user/john/shop

我的路由.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页面还在显示

我尝试按照教程中的说明进行操作,但没有任何效果

【问题讨论】:

  • 你的控制器不是叫ProfilesController吗?
  • 是的,它应该被称为 Profiles - 约定。会不会是问题?
  • 可能是这个问题,你可以把'controller' => 'profile'改成'controller' => 'profiles'试试

标签: php cakephp redirect


【解决方案1】:

我认为是因为有“,”更多。

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
    )
);

【讨论】:

  • 我不明白,对不起,你能解释一下吗?
  • 好的,在你的 'action' => 'index' 之后有一个逗号你不需要这个:Router::connect('/profile/:profile_name/shop', array('controller' => 'profile','action' => 'index' , array('pass' => array('profile_name') )));
猜你喜欢
  • 2018-02-24
  • 1970-01-01
  • 1970-01-01
  • 2013-06-05
  • 2013-11-27
  • 2014-04-30
  • 2011-09-16
相关资源
最近更新 更多