简体   繁体   English

Codeigniter URL重写问题

[英]Codeigniter URL ReWriting Issue

I am working a codeigniter project. 我正在工作一个codeigniter项目。 for example I have a controller Blog and a method category with param. 例如,我有一个控制器Blog和一个带有param的方法类别。 When i go to a link <a href="domain.com/blog/category/2">Developer Blog</a> it works fine. 当我转到链接<a href="domain.com/blog/category/2">Developer Blog</a>它可以正常工作。 which redirect to a page developer blog . 重定向到页面developer blog Is it possible to rewrite the url as domain.com/blog/developer-blog dynamically ? 是否可以动态将URL重写为domain.com/blog/developer-blog Thank you. 谢谢。

Open your application/config/routes.php and try following (if you want exact as mentioned in question) 打开您的application/config/routes.php并尝试执行以下操作(如果您要确切地提及问题)

$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 所以你的URL现在应该看起来像https://domain.com/blog/developer-blog/1https://domain.com/blog/developer-blog/2

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

for more see http://www.codeigniter.com/user_guide/general/routing.html 有关更多信息,请参见http://www.codeigniter.com/user_guide/general/routing.html

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

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