如何让 CodeIgniter 接受“查询字符串"网址? [英] How to make CodeIgniter accept "query string" URLs?
本文介绍了如何让 CodeIgniter 接受“查询字符串"网址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
根据 CI 的文档,CodeIgniter 使用基于分段的方法,例如:
According to CI's docs, CodeIgniter uses a segment-based approach, for example:
example.com/my/group
如果我想找一个特定的组(id=5),我可以访问
If I want to find a specific group (id=5), I can visit
example.com/my/group/5
在控制器中,定义
function group($id='') {
...
}
现在我想使用传统方法,CI 将其称为查询字符串"URL.示例:
Now I want to use the traditional approach, which CI calls "query string" URL. Example:
example.com/my/group?id=5
如果我直接访问这个 URL,我会得到一个 404 页面未找到.那么我该如何启用它?
If I go to this URL directly, I get a 404 page not found. So how can I enable this?
推荐答案
为了可靠地使用查询字符串,我发现你需要做 3 件事
For reliable use of query strings I've found you need to do 3 things
- 在
application/config/config.php
中设置$config['enable_query_strings'] = true;
- 再次在
application/config/config.php
设置$config['uri_protocol'] = "PATH_INFO";
- 更改您的 .htaccess 以删除 ?(如果存在)在重写规则中
我使用以下内容
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
这篇关于如何让 CodeIgniter 接受“查询字符串"网址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文