404 Page Not Found The page you requested was not

2019-07-07 03:21发布

问题:

i have developed a web app on code igniter .. this is the first time i am working on code-igniter .. after developing a web application on my localhost .so i decided to put my code-igniter web app on the temporary free server.. so i uploaded my site on this site 1freehosting... and then i imported my database .. after that i have changed the settings of database in database.php file .. and also i changed the base url in config.php file ..as this is my domain name http://hello.hostingsiteforfree.com/... so i changed it to this url .. but then i am getting a following error ... i dont know what is going wrong ..i have searched a lot but nothing helps.. and also i am forgot to mention that my .htaccess file is empty ..means there is not a single line in it

this is the error i am getting

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 */

my controller

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

class LoginController extends 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 file

   $config['base_url']  = 'http://hello.hostingsiteforfree.com/';
   $config['index_page'] = 'index.php';

回答1:

Since you do not have any .htaccess to edit you url you must add an index.php when calling a controller like

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

I tried accessing it via the url above and it works, but the database connection is not set up properly

in your config file where there is $config['index_page'] = '' if it is blank add an index.php to it

Check to see it works



回答2:

Look at your application/routes.php and make sure that your $route['default_controller'] is correctly set to your default controller. As follows, this is my routes.php:

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

Also, make sure that your default controller (in my case, its application/controllers/home_controller.php and within it is class Home extends CI_Controller {...}

--

If that doesn't work, make sure your default controller is correctly calling your default view and loading it as such:

$this->load->view('home_view', $data);

--

If THAT doesn't work, then take a look at your application/config/config.php and make sure that the following are correctly set as follows IF you want to get rid of your index.php in the url (for clean urls):

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

and if you're going for clean urls, do post your .htaccess (which should follow something like this: http://www.farinspace.com/codeigniter-htaccess-file/) so we can look at it in further detail and try to fix it if none of the above fix it.



回答3:

Have you removed index.php with .htaccess? If not then put it in the end.