繁体   English   中英

在Codeigniter中使用htaccess更改动态网址

[英]Change Dynamic Url using htaccess in codeigniter

我具有以下网址结构:www.mysite.com/temporary/articles.php/artid=1

我想使用以下网址进行更改:www.mysite.com/temporary/articles/article-title-here。

文章标题应基于artid。 任何人都可以告诉我该怎么做?

不需要.htaccess。 我将创建另一个控制器方法并添加一些路由。 我将使用以下方法:

  1. 您提交以下URL: www.mysite.com/temporary/articles.php/artid=1
  2. CI会捕获并重新路由,如下所示:在您的route.php中:

     $route['temporary/articles.php/artid=(:any)'] = "temporary/articles/search_by_id/$1"; 
  3. 在您的控制器中:

     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") } } 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM