使用CodeIgniter删除url中的index.php

使用CodeIgniter删除url中的index.php,php,apache,codeigniter,Php,Apache,Codeigniter,我正在开发一个基于Ubuntu、Apache2和CodeIgniter的应用程序 我有一个名为Site的控制器,如下所示 class Site extends CI_Controller { public function view($page = 'home') { $this->load->view('site/'.$page, $data); } } 在application/views/site中,我有home.php和about.p

我正在开发一个基于Ubuntu、Apache2和CodeIgniter的应用程序

我有一个名为
Site
的控制器,如下所示

class Site extends CI_Controller {
    public function view($page = 'home')
    {
        $this->load->view('site/'.$page, $data);
    }
}
application/views/site
中,我有
home.php
about.php

localhost/index.php/about
运行良好
但是
localhost/about
get
未找到,在此服务器上未找到请求的URL/about。

我已经

  • 确保启用了“修改重写”,并在apache2配置文件中允许覆盖所有内容
  • $config['index_page']=''
    in
    application/config/config.php
  • 我还设置了一条路线

    $route['default_controller'] = "site/view";  
    $route['404_override'] = '';   
    $route['(:any)'] = "site/view/$1";
    
    这是我的
    .htaccess

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]  
    
    <Files "index.php">
    AcceptPathInfo On
    </Files>  
    
    重新编写引擎打开
    重写cond%{REQUEST_FILENAME}-F
    重写cond%{REQUEST_FILENAME}-D
    重写规则^(.*)$index.php/$1[L]
    上的AcceptPathInfo
    
    这是我正在使用的.htaccess(在Yii上,但应该是可交换的):


    与您的几乎相同

    请尝试跟随本页了解。你的规则看起来是正确的,但我对正则表达式很糟糕


    需要研究的一些事情是使用phpinfo()检查mod_rewrite是否可用;。该链接中的第三步还讨论了使用a2enmod启用mod_重写。并确保从我的codeigniter网站重新启动Apache。

    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond $1 !^(index\.php|resources|robots\.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L,QSA] 
    </IfModule>
    
    
    重新启动发动机
    1美元^(索引\.php | resources | robots\.txt)
    重写cond%{REQUEST_FILENAME}-F
    重写cond%{REQUEST_FILENAME}-D
    重写规则^(.*)$index.php/$1[L,QSA]
    
    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond $1 !^(index\.php|resources|robots\.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L,QSA] 
    </IfModule>