【发布时间】:2015-09-16 20:11:07
【问题描述】:
重定向所有更改/重复的网址
/changed-title/2
/another-changed-title/2
更正网址
/original-correct-title/2
例如
http://stackoverflow.com/questions/232323/original-title-of-question
如果我更改 url (slug) 的最后一部分并按回车键
http://stackoverflow.com/questions/232323/changed-title-of-question-duplicate
仍会使用正确的 slug 重定向到正确的网址
在当前页面试试
我也想做同样的事
我正在使用 symfony 框架
routing.yml
topic_item_redirect:
path: /topic/{title}/{id}
defaults: { _controller: AppBundle:Topic:redirectToItem }
topic_item:
path: /topic/{title}/{id}
defaults: { _controller: AppBundle:Topic:item }
TopicController.php
public function redirectToItemAction($title,$id) {
$title = $this->getDoctrine()->getManager()->getConnection()
->fetchColumn(
'select title from topic where id = ?',
[$id]);
// action which renders topic
return $this->redirectToRoute('topic_item',['title'=>$title,'id'=>$id],301);
}
这种方法不适合我
【问题讨论】:
标签: php .htaccess symfony redirect