Codeigniter 中的 URI 路由
我的 CI 网站运行良好,只是 URL 有点难看。 我应该采取什么方法来路由显示的内容:
http://domain.com /content/index/6/Planning
到网址:
我很困惑是否应该在路由文件中或在我的 .htaccess 中完成此操作,
谢谢
I have my CI site working well except the URL's are a bit ugly.
What approach should I take to enable me to route what is displaying at:
http://domain.com/content/index/6/Planning
to the url:
I'm confused about whether this should be be done in the routes file or in my .htaccess
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
http://codeigniter.com/user_guide/general/routing.html
你应该能够通过本页上的一些示例来实现这一点
http://codeigniter.com/user_guide/general/routing.html
you should be able to accomplish that with some of the examples on this page
有几种方法可以设置 config/routes.php,适合性取决于您的要求。
每个页面的路由,如果您只想路由几个页面:
您可以使用后备 url,它将在所有其他路由规则之后匹配 - 这意味着您必须设置在后备规则之前可能匹配此规则的规则。这也意味着你失去了ID,并且必须根据标题查询数据库:
或者你可以制定策略,所有内容的URL必须以大写字母开头,在这种情况下,你不必担心其他路由规则
你仍然需要数字 ID,所以你不必更改控制器/模型:
There are couple of ways to set up config/routes.php, the suitability depends on your requirements.
Route for each page, if you have just a couple of pages that you want to route:
You can use fallback url, that will match after all other route rules - that means you must set rules that might match this rule before the fallback rule. It also means you loose ID, and have to query database based on the title:
Or you can have policy that all urls to content must start with capital letter, in that case you don't have to worry about other route rules
You still want the numerical ID, so you don't have to change the controller/model: