【问题标题】:(issue) redirect route cakephp(issue) 重定向路由 cakephp
【发布时间】:2016-11-23 02:47:21
【问题描述】:

对不起,我的英语太差了。

在 CakePHP 2.x 中,我想将旧链接重定向到我网站中的新链接。但我遇到了一些问题。

例子:

mywebsite.com/news/news 重定向到 mywebsite.com/news 我用:

 Router::redirect ('/news/news',
    array('controller' => 'categories', 
        'action' => 'index', 
        'slug' => 'news'
    ),
    array(
        'status' => '301'
    )
);
Router::connect('/news', array(
    'controller' => 'categories', 
    'action' => 'index', 
    'slug' => 'news'
));

=> 好的,可以了。

但是

示例: mywebsite.com/news/news/a-b-c 重定向到 mywebsite.com/news/a-b-c

我用:

    Router::redirect('/news/news/:slug',
    array(
        'controller' => 'articles',
        'action' => 'view',
        'category' => 'news'
    ),
    array(
        'status' => '301'
    )
);

Router::connect('/news/:slug',
    array(
        'controller' => 'articles',
        'action' => 'view',
        'category' => 'news'
    )
);

=> 结果是:mywebsite.com/articles/view/category:news

请帮忙,谢谢!

【问题讨论】:

    标签: cakephp redirect routes


    【解决方案1】:

    您正在将所有请求从 news/news/* 重定向到 articles/view/category:*

    你需要那里的 301 重定向吗?

      Router::connect('/news/news/:slug',
        array(
            'controller' => 'news',
            'action' => 'slug'
        )
    );
    

    但在此基础上,控制器将期望为每种类型的 a-b-c 动作定义一个动作,这些动作可以作为 slug 传递

    【讨论】:

    • a-b-c 是蛞蝓。我需要重定向到 /news/:slug :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-04-17
    • 1970-01-01
    • 2012-04-12
    • 2020-04-22
    • 1970-01-01
    • 1970-01-01
    • 2017-04-15
    相关资源
    最近更新 更多