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/

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值