Ubuntu 16.04 中的 CodeIgniter

CodeIgniter in Ubuntu 16.04

我正在尝试将我的 CI 项目从 windows 中的本地主机移动到 Ubuntu。我正在与:

在我的cognfig.php

$config['base_url'] = '';

$config['index_page'] = 'index.php';

我的虚拟主机:

<VirtualHost *:80>

  # Admin email, Server Name (domain name) and any aliases
  ServerAdmin mymail@mymail.com
  ServerName  mywebiml.com
  ServerAlias www.mywebiml.com


  # Index file and Document Root (where the public files are located)
  DirectoryIndex index.php
  DocumentRoot /var/www/html/CLASE

</VirtualHost>

CI 应用程序的根文件夹是 "CLASE"。 另外,我在 /etc/hosts

中添加了条目
MyIp   mywebiml.com
MyIp   www.mywebiml.com

问题是,当我尝试访问我的页面时,我不断收到来自 CI 的自定义 404 错误。

首先你必须给 $config['base_url'] 一个值。使用以下

$config['base_url'] = 'http://mywebiml.com/';

其次,确保您使用的文件和 class 命名方案 CI 要求。 Class 文件必须以类似 Ucfirst 的方式命名,而任何其他文件名(配置、视图、通用脚本等)都应全部小写。

差:

some_class.php

好:

Some_class.php

Class 名称应始终以大写字母开头。多个单词应该用下划线分隔,而不是 CamelCased。

差:

class someClass {

好:

class Some_class {

文件名和 class 名称必须完全相同 - 区分大小写。

以上规则在基于 Windows 的开发环境中无关紧要,但在像 Ubuntu.

这样的 linux 系统中会起作用

如果您使用 .htaccess 重写 URL 以便删除 index.php,请使用以下内容。

$config['index_page'] = '';