远程服务器上的CodeIgniter默认页面

时间:2013-08-15 01:09:06

标签: codeigniter

我对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';

sportstreamapplication/controllers/文件夹中的控制器名称。根据我没有使用CI(或任何其他框架)的经验,远程服务器上index.php文件夹内的public_html文件是访问站点时默认加载的文件。但是,使用CI,每当我尝试访问我的域名时,都会返回404错误。我试过设置为base_urlhttp://www.mysite.com没有任何运气。

有没有人知道如何制作,以便在访问http://www.mysite.comhttp://www.mysite.com/sportstream将被加载?

2 个答案:

答案 0 :(得分:3)

您需要在RewriteBase文件中添加.htaccess

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

注意:我也在?之后添加了index.php

我还会将follow设置为空字符串(在您尝试上述操作后):

$config['base_url'] = '';
$config['index_page'] = '';

最后,在您的routes.php文件中:

$route['default_controller'] = 'sportstream';

更新

application/config/database.php中,您需要更改数据库驱动程序。在您的localhost上,MySQLi是数据库驱动程序集。但是,在远程服务器上,没有安装MySQLi,因此将其更改为MySQL应该可以解决问题。

//old - works on local server
$db['default']['dbdriver'] = 'mysqli';

//new - works on remote server
$db['default']['dbdriver'] = 'mysql';

由于某种原因,Codeigniter只是“中断”并显示空白屏幕没有错误。

答案 1 :(得分:0)

您必须在$route['default_controller'] ="sportstream";中设置默认控制器,它位于aplication / config / route.php , So when visiting http://www.mysite.com/ the sportstream`控制器将默认加载。

检查User guide

中的默认控制器

切换回$config['index_page'] = '';

如果您重命名为index.php,则必须在index_page中输入config名称,否则您可以将其保留为空白。

推荐的Codeigniter入门指南:http://net.tutsplus.com/tutorials/php/codeigniter-basics/