我有以下网址结构: www.mysite.com/temporary/articles.php/artid=1
我想改为: www.mysite.com/temporary/articles/article-title-here。
其中文章标题应基于artid。 任何人都可以告诉我该怎么做?
答案 0 :(得分:0)
不需要.htaccess。我会创建另一个控制器方法并添加一些路由。我会使用以下方法:
www.mysite.com/temporary/articles.php/artid=1
CI抓住它并重新路由它: 在您的routes.php中:
$route['temporary/articles.php/artid=(:any)'] = "temporary/articles/search_by_id/$1";
在您的控制器中:
class Articles extends CI_Controller {
public function index($title){
//load your model
//from your model, query your database to get your article info by title
//send results to your view.
}
public function search_by_id($id){
//load your model
//from your model, query your database to get your article title by id. Set it = $title
redirect("temporary/articles/$title")
}
}