[英]Change Dynamic Url using htaccess in codeigniter
I have the following url structure: www.mysite.com/temporary/articles.php/artid=1 我具有以下网址结构:www.mysite.com/temporary/articles.php/artid=1
I would like to change it with: www.mysite.com/temporary/articles/article-title-here. 我想使用以下网址进行更改:www.mysite.com/temporary/articles/article-title-here。
where article-title should be based on artid . 文章标题应基于artid。 Anyone can tell me how can I do that? 任何人都可以告诉我该怎么做?
No .htaccess needed. 不需要.htaccess。 I would create another controller method and add some routes. 我将创建另一个控制器方法并添加一些路由。 I would use the following approach: 我将使用以下方法:
www.mysite.com/temporary/articles.php/artid=1
您提交以下URL: www.mysite.com/temporary/articles.php/artid=1
CI catches it and reroutes it as such: In your routes.php: CI会捕获并重新路由,如下所示:在您的route.php中:
$route['temporary/articles.php/artid=(:any)'] = "temporary/articles/search_by_id/$1";
In your Controller: 在您的控制器中:
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.