404页面未找到您请求的页面未找到。CodeIgniter

3
我在CodeIgniter上开发了一个Web应用程序,这是我第一次使用CodeIgniter。在本地环境中开发Web应用程序后,我决定将我的CodeIgniter Web应用程序上传到临时免费服务器1freehosting。然后,我导入了我的数据库,并在database.php文件中更改了数据库设置。我还在config.php文件中更改了基础URL,因为这是我的域名http://hello.hostingsiteforfree.com/,所以我将其更改为此URL。但是我遇到了一个错误,不知道出了什么问题。我已经搜索了很多,但没有找到解决方法。另外,我忘记提到我的.htaccess文件为空,意味着里面没有一行代码。以下是我收到的错误信息:
404 Page Not Found

The page you requested was not found.

routes.php

    <?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

 $route['default_controller'] = "loginController";
$route['404_override'] = '';


 /* Location: ./application/config/routes.php */

我的控制器

   <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

类 LoginController 继承自 CI_Controller {

 function index(){

    $new['main_content'] = 'loginView';
    $this->load->view('loginTemplate/template', $new); 

}




function verifyUser(){

    //getting parameters from view 
    $data = array(
            'username' => $this->input->post('username'),
            'password' => $this->input->post('password')
    );


    $this->load->model('loginModel'); 
    $query = $this->loginModel->validate($data);


          if ($query){             //if the user c validated
        //data variable is created becx we want to put username in session
            $data = array(
                'username' => $this->input->post('username'),
                 'is_logged_in' => true 
            );

           $this->session->set_userdata($data);
         redirect('sessionController/dashboard_area');
    }
    else
     {
        $this->index();
    }
}
function logout()
{
    $this->session->sess_destroy();
    $this->index();
}
}



?>

配置文件
   $config['base_url']  = 'http://hello.hostingsiteforfree.com/';
   $config['index_page'] = 'index.php';
3个回答

4

由于您没有任何.htaccess文件来编辑URL,因此在调用控制器时必须添加index.php,例如:

http://hello.hostingsiteforfree.com/index.php/loginController

我尝试使用上面的URL进行访问,它可以工作,但是数据库连接未正确设置。

在您的配置文件中,如果$config['index_page'] = ''为空,请将其添加index.php

检查以确保它是否正常工作。


谢谢,它有效了。谢谢。你能告诉我该怎么做才能通过这个网址http://hello.hostingsiteforfree.com访问它吗?我想让您知道我的config[index_page]不是空的... - mynameisjohn
@mynameisjohn 这是一个关于如何处理 CodeIgniter 中 .htaccess 问题的主题。http://www.farinspace.com/codeigniter-htaccess-file/ - tomexsans
搜索了一百多年后,我终于找到了正确的答案。谢谢! - Jenuel Ganawed

1

查看您的application/routes.php并确保您的$route['default_controller']已正确设置为您的默认控制器。如下所示,这是我的routes.php:

$route['default_controller'] = "home";
$route['404_override'] = '';

此外,请确保您的默认控制器(在我的情况下,它是 application/controllers/home_controller.php,其中包含 class Home extends CI_Controller {...})。

--

如果那不起作用,确保您的默认控制器正确调用您的默认视图并将其加载为这样:
$this->load->view('home_view', $data);

--

如果这不起作用,那么请查看您的application/config/config.php文件,并确保以下内容正确设置,以便在URL中去掉index.php(用于清除URL):

$config ['index_page'] =''; $config ['uri_protocol'] ="AUTO";

如果您想要干净的URL,请发布您的 .htaccess 文件(应该遵循类似于 http://www.farinspace.com/codeigniter-htaccess-file/ 的格式),以便我们进一步查看并尝试修复它,如果以上方法都无法解决问题。

好消息是,你的http://hello.hostingsiteforfree.com/license.txt显示正确。但我猜你还没有修改你的.htaccess文件,因为http://hello.hostingsiteforfree.com/license无法工作。 - jsanc623
感谢您的帮助...请查看我的控制器是否存在任何问题,或者我没有正确加载视图,则肯定会在本地主机上出现错误...但它可以成功运行...至于htaccess文件...我有我的htaccess文件在应用程序文件夹中...里面什么也没有...我的意思是它是空白的...不知道该写什么。 - mynameisjohn
jsanc623 我更新了我的问题.. - mynameisjohn
如果是这样的话,我认为它一开始就不应该工作...因为它在本地主机上运行...好吧,我已经匹配了大小写,但是还是没有用...仍然给我同样的错误。 - mynameisjohn
抱歉,我在检查自己的CI后编辑了我的评论。你能发布一下你的config.php文件的上半部分吗?就是我之前提到的那些($config['index_page'])。 - jsanc623
显示剩余7条评论

0
你是否使用 .htaccess 移除了 index.php?如果没有,请将它放在最后。

我没听懂你的意思...我的htaccess文件是空的...而且根目录下有一个index.php文件。 - mynameisjohn

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接