【发布时间】:2012-03-03 06:23:44
【问题描述】:
全部,
我目前正在使用 CakePHP 来彻底改造我当前的 NEWS 网站。我已经或将把所有当前文章转移到我的新站点,它们将采用与当前站点相同的article_id。但是,我意识到了以下问题。
我当前的站点使用以下设置作为 URL:
http://www.mydomain.com/?c=140&a=4388
c=references 类别 ID,a=references 文章 ID。我的新设置 (CakePHP) 我利用了 slugs,现在我的文章 URL 显示为:
http://www.mydomain.com/noticia/this-is-an-article-slug
由于我通过 webstats 注意到,我的许多文章都是通过 Facebook 等其他网站上设置的链接访问的,我认为创建一个系统/路由来为我解决这个问题至关重要。
这就是我的想法:
- 创建一个检测与上述类似的请求的路由
- 使路由将
a值作为参数传递给我的文章控制器中的重定向函数,例如articleRedirect($article_id) -
然后此函数将根据传递的
$article_id在数据库中查找slug并重定向到新地址(参见下面的函数)// Function in articles controller to redirect old site's article url to // new websites url format function articleRedirect($article_id = NULL){ $this->Article->recursive = -1; $slug = $this->Article->findById($article_id); if($slug == NULL){ $this->Session->setFlash('Article not found'); $this->redirect('/noticias'); }else{ $this->redirect('/noticia/'.$slug['Article']['slug']); } }
我认为这应该可行。但是,我在路由方面需要一些认真的帮助。谁能推荐一条我可以使用的路线。
非常感谢。
【问题讨论】:
标签: cakephp routing cakephp-1.3 routes