以下问题都容易解决,在此简述
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/
本文介绍了解决Apache服务器上URL重写问题的方法,并详细解释了如何通过修改.htaccess文件来实现CI框架项目的友好URL。同时,还讨论了如何调整配置以去除URL中的index.php。

3052

被折叠的 条评论
为什么被折叠?



