我想在 kohana 中使用 SEO url,我已经使用了 htaccess 文件,所以我可以拥有 www.food.com/food/3123
编号:3123 标题:热狗
但这对 SEO 不友好,我怎么才能把它转到 www.food.com/food/hotdog 呢?或 www.food.com/food/I-love-hotdog ?
用 hotdog 或 I-love-hotdog 搜索数据库是错误的,对吗?
我读到一些人说这样做 www.food.com/food/3123/hotdog 或 www.food.com/food/hotdog3123 然后解析它
有人有正确的方法吗?或者更好的结构?
最佳答案
用“hotdog”或“I-love-hotdog”搜索就可以了。您可以将附加字段存储在名为“url”的数据库表中(例如)。请注意,“url”字段必须是唯一的。然后在 application/bootstrap.php
中创建正确的路由,这些路由将满足您采用产品的 url
部分的请求,然后使用 Controller 在数据库中搜索它。
使 http://stackoverflow.com/questions/10202703
自动重定向到 http://stackoverflow.com/questions/10202703/seo-urls-with-kohana-strategy
可以通过 Kohana 的 $this->request->redirect()
(Request::redirect()
) 方法实现。在 Controller 中,您获取项目的 ID(在我们的示例中为 10202703
),然后找到项目的相应 URL (seo-urls-with-kohana-strategy
) 并重定向到 $this->request->uri().'/'.$item_url
通过 $this->request->redirect('/'.$this->request->uri(). '/'.$item_url)
关于php - 使用 kohana 策略的 SEO 网址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10202703/