codeigniter中的url\u后缀工作不正常

codeigniter中的url\u后缀工作不正常,codeigniter,Codeigniter,我是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"; 到config.php文件,为所有页面提供默认后缀

我是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";
到config.php文件,为所有页面提供默认后缀。之后,我用以下代码创建了一个controller test.php:

class Test extends Controller{

function test(){
    parent::Controller();
}

function index(){
    $this->load->view('test');
}
}

还有一种观点:

<?php
    echo anchor(current_url(), 'This Page');
?>

当我导航到它时,它工作正常,但当我在视图中单击anchor()函数自动生成的链接时,它会转到

如何从anchor()函数生成的URL中删除/index.php/

当我指向主页时也是如此

localhost/ci/index.html

它向我显示了一个404页面未找到错误,但当我指向

localhost/ci/index.php


它很好用。为什么主页没有转换为index.html而不是index.php?

您必须使用htaccess创建重写条件。 要删除index.php,请将其添加到根文件夹.htaccess文件中

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*) /index.php/$1 [L]
如果您将加载测试作为默认控制器,那么这将是您的基本url

本地主机/ci/ 或 localhost/ci/test/ 或 localhost/ci/test/index.html

确保将config.php设置为

$config['index_page'] = ''
您还应该使用Codeigniter 2.1来获得正确的PHP5支持

如果使用PHP5,构造函数函数也应该是这样。否则,请坚持使用PHP4

public function __construct()
{
    parent::__construct();
}