编码器找不到控制器


Codeigniter cannot find controller

我使用Codeigniter 3。当在本地wamp服务器上运行时,一切都很好。但是,当在我的VPS (Linux Debian Apache 2.2.22)上运行时,我得到一个"URL未找到"的消息。

这里是控制器:

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
    class Contact extends CI_Controller {
      public function __construct()
      {
        parent::__construct();
        $this->load->helper('url');
        $this->load->library('session');
        $this->load->helper('form');
    }
    public function index()
    {
      $this->load->view('contact_view');
    }
  }

这个控制器的URL是www.example.com/Contact

错误信息是:

请求的URL/index.php/Contact在此服务器上找不到。

我已经从$config['index_page'] = ''中删除了index.php

在我的。htaccess文件中,我使用重写来消除url中对index.php的需要,使用如下:

RewriteEngine on RewriteCond $1 !^(index'.php|resources|robots'.txt) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L,QSA]

我的虚拟主机上的指令是:
<Directory "/var/www/example"> Options Indexes FollowSymLinks AllowOverride All Order allow,deny Allow from all </Directory>

mod_rewrite在虚拟主机上肯定是启用的。

一切工作正常在我的本地机器,运行Wampserver,但为什么它不工作在我的VPS?

对于Codeigniter 3,我必须将Controller文件名的第一个字母大写。比如,我把main。php改成了main。php这就解决了问题。

请注意,我不必在我的本地主机windows笔记本电脑上这样做,但我必须在hostgator unix服务器上这样做。

RewriteRule ^(.*)$ index.php?/$1 [L]

index.php后面的问号是解决方案…然而,我也想要一些解释。根据经验,我知道有些服务器需要它,但不知道确切的原因。