Codeigniter The requested URL was not found on this server

Emjey23 picture Emjey23 · Apr 24, 2018 · Viewed 13.6k times · Source

I am learning Codeigniter and I can't solve the problem I am having.

  • When the user access localhost/reservation/, the system will display the login.php and
  • When the user click the login button, the system should redirect the user to another view which the system will display book.php.

A good explanation is very appreciated.

View

<form class="" method="POST"> 
   <div>
       <button class="btn btn-primary" name="login">Login  </button>
   </div>
</form> 

As you can see, I don't include username and password input fields to shorten the codes.

Controller

class Reservation extends CI_Controller {
public function _construct()
{
    parent::__construct(;
    $this->load->helper("url");
}

public function index()
{
    if(...some condition...){
        redirect('book');
    }
    $this->load->view('login');
}

public function book(){
    $this->load->view('book');
}
}

I shorten the code, removed unnecessary ones(in my opinion) to make it shorter and direct to the point.

Routes

$route['book'] = 'reservation/book';
$route['default_controller'] = 'reservation';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;

.htaccess

<IfModule authz_core_module>
    Require all denied
</IfModule>
<IfModule !authz_core_module>
    Deny from all
</IfModule>

Answer

Pradeep picture Pradeep · Apr 24, 2018

Your .htaccess should be like this (removing index page):

Options +FollowSymlinks -Indexes
RewriteEngine on

DirectoryIndex index.php
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

put .htaccess file to your app folder outside application folder

and set your config.php like this :

$config['base_url'] = 'http://localhost/app_folder/';
$config['index_page'] = '';

Now access

http://localhost/app_folder/ 

will show you your login page