我正在尝试将我的 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/';
其次,确保您使用的是 CI 所需的文件和类命名方案。类文件必须以类似 Ucfirst 的方式命名,而任何其他文件名(配置、 View 、通用脚本等)都应全部小写。
坏的:
some_class.php
好的:
Some_class.php
类名应始终以大写字母开头。多个单词应该用下划线分隔,而不是 CamelCased。
坏的:
class someClass {
好的:
class Some_class {
文件名和类名必须完全相同——区分大小写。
上述规则在基于 Windows 的开发环境中无关紧要,但在像 Ubuntu 这样的 linux 系统上会很重要。
如果您使用
.htaccess
重写 URL,所以 index.php
被删除使用以下。$config['index_page'] = '';
关于Ubuntu 16.04 中的 CodeIgniter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50609466/