【问题标题】:404 Page Not Found The page you requested was not found. Code igniter [closed]404 Page Not Found 找不到您请求的页面。代码点火器[关闭]
【发布时间】:2013-01-13 12:51:11
【问题描述】:

我已经在 code igniter 上开发了一个 web 应用程序 .. 这是我第一次在 code-igniter 上工作 .. 在我的 localhost 上开发了一个 web 应用程序之后。所以我决定把我的 code-igniter 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';

【问题讨论】:

    标签: php .htaccess codeigniter webserver hosting


    【解决方案1】:

    由于您没有任何 .htaccess 来编辑您的网址,您必须添加一个 index.php 当调用像

    这样的控制器时

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

    我尝试通过上面的 url 访问它,它可以工作,但是数据库连接没有正确设置

    在有$config['index_page'] = '' 的配置文件中,如果它是空白的,添加index.php 到它

    检查它是否有效

    【讨论】:

    • 谢谢你它工作..谢谢..你能告诉我应该怎么做才能通过这个 url hello.hostingsiteforfree.com 访问它,我让你知道我的 config[index_page] 不是空白的......
    • @mynameisjohn farinspace.com/codeigniter-htaccess-file 这是使用 codeigniter 处理 .htaccess 问题的主题
    • 找了一百多年,终于找到了正确的答案。谢谢男人
    【解决方案2】:

    查看您的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/),以便我们可以更详细地查看它,如果上述修复都没有,请尝试修复它它。

    【讨论】:

    • 好消息是您的hello.hostingsiteforfree.com/license.txt 显示正确。但我猜你还没有修改你的 .htaccess,因为hello.hostingsiteforfree.com/license 不起作用。
    • 感谢您的帮助...看看我的控制器中是否有任何问题,或者我没有正确加载视图,那么它肯定会给我本地主机上的错误..但是它成功地工作了......对于htaccess文件..我在应用程序文件夹中有我的htaccess文件..那里没有任何东西..我的意思是它是空白的..不知道在那里写什么
    • @mynameisjohn 能否发布您的默认控制器、routes.php 和默认视图代码,以便我们查看?它返回 404,因为路由没有找到任何东西......
    • jsanc623 我更新了我的问题..
    • 好吧,如果是这样的话,那么我认为它首先不应该工作..因为它在本地主机中工作..我已经匹配了这个案例,但又一次..没有任何工作..给我同样的错误
    【解决方案3】:

    您是否使用 .htaccess 删除了 index.php?如果没有,那就把它放在最后。

    【讨论】:

    • 我没听明白……我的 htaccess 文件是空的……是的,根目录中存在 index.php 文件
    猜你喜欢
    • 2017-10-13
    • 2018-04-18
    • 2018-04-18
    • 2016-01-12
    • 2013-07-06
    • 2012-12-30
    • 2014-02-16
    • 2017-06-19
    • 2011-11-09
    相关资源
    最近更新 更多