Codeigniter 项目在本地工作但不在线 - 找不到 404 页面
Codeigniter project works local but not online - 404 page not found
正如标题所说,我已经搜索了很多,尝试了一些修复,但它仍然无法在在线服务器上运行。在网上,我一直收到 404 页面未找到。当它在本地 运行 时,它就像一个魅力。
目前这是我的配置。
public_html/application/config/config.php:
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
我试过将 base_url 更改为站点域:http://junkfoodmountain.com/
尝试将 index_page 更改为 index.php 并更改为无
尝试将 uri_protocol 更改为所有其他可能的。
public_html/.htaccess
Options -Indexes
RewriteEngine on
RewriteBase /
RewriteCond !^(index\.php|assets|phpmyadmin|robots\.txt)
RewriteRule ^(.*)$ /index.php?/ [QSA,L]
尝试过不使用 .htaccess 也不起作用。
服务器是带有 virtualmin 的 Ubuntu Server 14.04 LTS。这方面的所有配置都是默认的。当然,当您访问站点 link 时,它会显示 public_html
中的所有内容
更新 1:
全新安装后。这一切都在默认情况下工作。并逐一添加文件,我发现它与 routes.php 有关。更改
$route['default_controller'] = 'welcome';
到
$route['default_controller'] = 'main/index';
这是main.php
<?php
class main extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model('home_model');
}
public function index($page = 'home')
{
$menu['menu'] = $this->home_model->get_menu();
$data['servers_table'] = $this->servers_table($this->home_model->get_servers());
$this->load->view('templates/header', $menu);
$this->load->view('pages/'.$page, $data);
$this->load->view('templates/footer');
}
}
您可以尝试更改 .htaccess 文件中的值。曾经,我遇到过同样的问题,然后我可以用 .htaccess 解决它。我不记得我在上面做了什么。我不能说改变
我发现您应该以大写字母作为首字母来调用您的控制器。更改
main.php > Main.php
和
class main extends CI_Controller > class Main extends CI_Controller
为我解决了问题
我遇到了同样的问题。我刚刚将控制器名称重命名为从 Home
到 home
.
的所有小写字符
正如标题所说,我已经搜索了很多,尝试了一些修复,但它仍然无法在在线服务器上运行。在网上,我一直收到 404 页面未找到。当它在本地 运行 时,它就像一个魅力。
目前这是我的配置。
public_html/application/config/config.php:
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
我试过将 base_url 更改为站点域:http://junkfoodmountain.com/
尝试将 index_page 更改为 index.php 并更改为无
尝试将 uri_protocol 更改为所有其他可能的。
public_html/.htaccess
Options -Indexes
RewriteEngine on
RewriteBase /
RewriteCond !^(index\.php|assets|phpmyadmin|robots\.txt)
RewriteRule ^(.*)$ /index.php?/ [QSA,L]
尝试过不使用 .htaccess 也不起作用。
服务器是带有 virtualmin 的 Ubuntu Server 14.04 LTS。这方面的所有配置都是默认的。当然,当您访问站点 link 时,它会显示 public_html
更新 1:
全新安装后。这一切都在默认情况下工作。并逐一添加文件,我发现它与 routes.php 有关。更改
$route['default_controller'] = 'welcome';
到
$route['default_controller'] = 'main/index';
这是main.php
<?php
class main extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model('home_model');
}
public function index($page = 'home')
{
$menu['menu'] = $this->home_model->get_menu();
$data['servers_table'] = $this->servers_table($this->home_model->get_servers());
$this->load->view('templates/header', $menu);
$this->load->view('pages/'.$page, $data);
$this->load->view('templates/footer');
}
}
您可以尝试更改 .htaccess 文件中的值。曾经,我遇到过同样的问题,然后我可以用 .htaccess 解决它。我不记得我在上面做了什么。我不能说改变
我发现您应该以大写字母作为首字母来调用您的控制器。更改
main.php > Main.php
和
class main extends CI_Controller > class Main extends CI_Controller
为我解决了问题
我遇到了同样的问题。我刚刚将控制器名称重命名为从 Home
到 home
.