简体   繁体   中英

Codeigniter URL ReWriting Issue

I am working a codeigniter project. for example I have a controller Blog and a method category with param. When i go to a link <a href="domain.com/blog/category/2">Developer Blog</a> it works fine. which redirect to a page developer blog . Is it possible to rewrite the url as domain.com/blog/developer-blog dynamically ? Thank you.

Open your application/config/routes.php and try following (if you want exact as mentioned in question)

$route['blog/developer-blog'] = 'blog/category/2';
$route['blog/user-blog'] = 'blog/category/3';

for dynamic routing you may use this

$route['blog/developer-blog/(:num)'] = 'blog/category/$1';
$route['blog/user-blog/(:num)'] = 'blog/category/$1';

so your URL now should be looks like https://domain.com/blog/developer-blog/1 , https://domain.com/blog/developer-blog/2

or https://domain.com/blog/user-blog/1 , https://domain.com/blog/user-blog/2 etc

for more see http://www.codeigniter.com/user_guide/general/routing.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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