Jamers Posted May 6, 2017 Report Share Posted May 6, 2017 一个项目中需要使用CI的Rewrite,需求如下: 需要将根目录的PHP文件调用CI,不想修改具体调用路径。CI目录为根目录下CI .htaccess设置如下: RewriteEngine On RewriteBase /CI/ RewriteRule ^([\d\w]*)\.php(.*)$ index.php/$1$2 [QSA,L] 结果配置后一直显示404错误,查apache日志,发现跳转链接是正确的,手工输入跳转链接可以正常使用。通过一般查找,发现默认CI使用的是$_SERVER['REQUEST_URI']值进行处理的,而通过rewrite跳转的值是原来请求的xxx.php,直接导致找不到指定控制器。修改application/config/config.php中的 /* |-------------------------------------------------------------------------- | URI PROTOCOL |-------------------------------------------------------------------------- | | This item determines which server global should be used to retrieve the | URI string. The default setting of 'REQUEST_URI' works for most servers. | If your links do not seem to work, try one of the other delicious flavors: | | 'REQUEST_URI' Uses $_SERVER['REQUEST_URI'] | 'QUERY_STRING' Uses $_SERVER['QUERY_STRING'] | 'PATH_INFO' Uses $_SERVER['PATH_INFO'] | | WARNING: If you set this to 'PATH_INFO', URIs will always be URL-decoded! */ $config['uri_protocol'] = 'PATH_INFO'; rewrite跳转后的链接值在$_SERVER['PATH_INFO']上,所以修改完成后就可以正常访问了。好象网上没太清晰的解释,如果有同样问题的朋友可以参考一下。 Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now