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