我是Codeigniter的新手并使用Codeigniter 1.7,我在根目录中创建了一个.htaccess文件,代码如下:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /ci/index.php/$1 [L]
从url中删除index.php,并添加
$config['url_suffix'] = ".html";
to config.php文件为所有页面提供默认后缀 . 之后我用这段代码创建了一个控制器test.php:
class Test extends Controller{
function test(){
parent::Controller();
}
function index(){
$this->load->view('test');
}
}
还有一个观点:
<?php
echo anchor(current_url(), 'This Page');
?>
当我导航到http://localhost/ci/test.html时它工作正常,但当我在我的视图中单击由anchor()函数自动生成的链接时,它会转到http://localhost/ci/index.php/test.html
如何从anchor()函数生成的url中删除/index.php/?
当我指向主页时
本地主机/ CI / index.html中
它向我显示404页面找不到错误,但是当我指向时
本地主机/ CI / index.php的
它工作正常 . 为什么主页没有转换为index.html而不是index.php?
1 回答
您必须使用htaccess创建重写条件 . 要删除index.php,请将其添加到根文件夹.htaccess文件中
如果您将Test加载为默认控制器,那么这将是您的基本URL
localhost / ci /或localhost / ci / test /或localhost / ci / test / index.html
确保将config.php设置为此
您还应该使用Codeigniter 2.1来获得正确的php 5支持 .
如果使用php 5,你的构造函数应该是这样的 . 否则坚持你拥有的php 4 .