Codeigniter无法找到控制器

时间:2015-08-17 00:00:59

标签: php apache .htaccess codeigniter mod-rewrite

我正在使用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');
    }
  }

此控制器的网址是www.example.com/Contact

错误信息是:

  

在此服务器上找不到请求的网址/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上不起作用?

2 个答案:

答案 0 :(得分:4)

对于Codeigniter 3,我不得不大写Controller文件名的第一个字母。例如,我将main.php更改为Main.php并为我修复了它。

请注意,我不必在我的localhost Windows笔记本电脑上执行此操作,但我必须在hostgator unix服务器上执行此操作。

答案 1 :(得分:1)

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

index.php之后的问号是解决方案......但是,我也想解释一下。我从经验中知道有些服务器需要它,但不知道确切的原因。

相关问题