我对 CI 比较陌生,我想知道是否有人知道如何设置 CI 的默认页面。我刚刚将文件从本地服务器传输到远程服务器,但遇到了一些问题。首先,我认为重要的是要注意我编辑了 .htaccess 文件,以便从 URL 中删除 index.php。
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
其次,在我的
config.php
文件,我有:$config['base_url'] = '';
$config['index_page'] = 'sportstream';
sportstream
是在 application/controllers/
中找到的 Controller 的名称文件夹。根据我不使用 CI(或任何其他框架)的经验,index.php
public_html
内的文件远程服务器上的文件夹是在访问站点时默认加载的文件夹。但是,使用 CI,每当我尝试访问我的域名时,都会返回 404 错误。我试过设置为 base_url
至 http://www.mysite.com没有任何运气。这里有人知道如何制作,以便访问时http://www.mysite.com那个http://www.mysite.com/sportstream会加载吗?
最佳答案
您需要添加一个 RewriteBase
在您的 .htaccess
文件:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
注意:我添加了一个
?
后 index.php
以及。我还将以下内容设置为空字符串(在您尝试上述操作后):
$config['base_url'] = '';
$config['index_page'] = '';
最后,在您的
routes.php
文件:$route['default_controller'] = 'sportstream';
更新
在
application/config/database.php
您需要更改数据库驱动程序。在您的本地主机上,MySQLi 是数据库驱动程序集。但是,在您的远程服务器上,未安装 MySQLi,因此将其更改为 MySQL 应该可以解决问题。//old - works on local server
$db['default']['dbdriver'] = 'mysqli';
//new - works on remote server
$db['default']['dbdriver'] = 'mysql';
出于某种原因,Codeigniter 只是“中断”并显示没有错误的空白屏幕。
关于远程服务器上的 CodeIgniter 默认页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18244819/