CI框架去掉index.php以及解决No input file specified问题

以下问题都容易解决,在此简述

1,打开apache的httpd.conf,开启rewrite_module,并且将AllowOverride None改为AllowOverride None。

2,在项目中,和index.php以及system文件夹同级的目录中,新建.htaccess文件,并写入一下代码


<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

这时,如果在浏览器访问首页,比如项目名为citest,当输入的url为
http://localhost/citest/Index/index时,会出现

No input file specified.

此时,只要将上述代码第四行中的

RewriteRule ^(.*)$ index.php/$1 [L]
修改为

RewriteRule ^(.*)$ index.php?/$1 [L]
即可,即在index.php与/之间添加一个?,这样就能够正常访问了。
不过在使用辅助函数site_url()和base_url()时,两个还是不太一样,

使用site_url时的路径为 http://localhost/citest/index.php

使用base_rul时的路径为 http://localhost/citest/

如果要去掉site_url中的路径,则在config.php中,将


$config['index_page'] = 'index.php';
修改为

$config['index_page'] = '';
即可
这样无论是site_url还是base_url的路径都为http://localhost/citest/

 


————————————————
版权声明:本文为CSDN博主「爱生活爱Coding」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/SKYYYF/article/details/77088610

posted @ 2019-12-24 10:41  帽子戏法  阅读(769)  评论(0编辑  收藏  举报
全部 html css js Linux php MySQL seo web git other 联系 管理