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

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/SKYYYF/article/details/77088610

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

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]
修改为

扫描二维码关注公众号,回复: 4591188 查看本文章
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/

猜你喜欢

转载自blog.csdn.net/SKYYYF/article/details/77088610
今日推荐