簡體   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