<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[Snooda]]></title> 
<link>http://www.snooda.com/index</link> 
<description><![CDATA[Snooda's Blog]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[Snooda]]></copyright>
<item>
<link>http://www.snooda.com/read/181</link>
<title><![CDATA[Codeigniter 从1.7.2升级2.0过程中关于url的问题]]></title> 
<author>snooda &lt;admin@snooda.com&gt;</author>
<category><![CDATA[默认分类]]></category>
<pubDate>Fri, 18 Feb 2011 03:20:34 +0000</pubDate> 
<guid>http://www.snooda.com/read/181</guid> 
<description>
<![CDATA[ 
	    昨天在从nginx1.7.2升级2.0的过程中发生了一个问题，不管url是什么，都会直接调用default_controller。经排查，问题发生在system/core/URI.php里面，在65行开始的一段代码里，是为CLI方式运行CI写的一段代码，在这里，程序被判断成CLI模式运行，然后试图获取_parse_cli_args，为空，于是调用default_controller。<br />
<br />
    我使用的webserver是nginx，在配置文件里用urlrewrite去掉了index.php，CI配置文件中的uri_protocol使用的AUTO。<br />
<br />
    CI2.0中判断是否为CLI方式运行的方法是判断$_SERVER[&#039;argv&#039;]是否为空，不为空就是CLI，为空就不是。我查php手册，上面是这样说的：When the script is run on the command line, this gives C-style access to the command line parameters. When called via the GET method, this will contain the query string. 也就是说$_SERVER[&#039;argv&#039;]不为空的时候还有一种可能，就是GET方式访问网页，那么该元素中的数据就是query string。也就是说CI2.0默认认为不能使用传统的query string方式，否则会导致误判为CLI。<br />
<br />
    然后继续分析，在nginx中rewrite的规则是********/index.php?$1，注意，用的是问号而不是斜杠，这是nginx的问题，假如用斜杠的话nginx会试图寻找index.php文件夹下的目标文件，会导致404。也就是说比我我请求的是http:/*****/clock，在ci那变成了http:/*****/index.php?clock，所以在判断时$_SERVER[&#039;argv&#039;]为clock，于是被判断成CLI，而在_parse_cli_args中，又是从$_SERVER[&#039;argv&#039;]数组的第二个元素开始取，clock作为第一个元素没有被取到，自然_parse_cli_args取到的是空，导致调用了默认控制器。<br />
<br />
    综上，有两种修正方法，方法1是暂时注释掉URI.php中判断CLI的那一段，方法2是更改config.php中的uri_protocol为QUERY_STRING。当然还有一种方法是修改nginx的rewrite规则，不使用问号，不过这个我不知道怎么改。
]]>
</description>
</item><item>
<link>http://www.snooda.com/read/181#blogcomment78</link>
<title><![CDATA[[评论] Codeigniter 从1.7.2升级2.0过程中关于url的问题]]></title> 
<author>Anoymous &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Sat, 26 Feb 2011 09:38:37 +0000</pubDate> 
<guid>http://www.snooda.com/read/181#blogcomment78</guid> 
<description>
<![CDATA[ 
	good!
]]>
</description>
</item><item>
<link>http://www.snooda.com/read/181#blogcomment103</link>
<title><![CDATA[[评论] Codeigniter 从1.7.2升级2.0过程中关于url的问题]]></title> 
<author>Anoymous &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Fri, 09 Sep 2011 07:43:45 +0000</pubDate> 
<guid>http://www.snooda.com/read/181#blogcomment103</guid> 
<description>
<![CDATA[ 
	呵呵，我个人不建议 uri_protocol 使用 AUTO，因为 CI 的判断有时候确实不太准确。
]]>
</description>
</item>
</channel>
</rss>