Emjey23
Emjey23

Reputation: 367

Codeigniter The requested URL was not found on this server

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

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>

Upvotes: 6

Views: 67026

Answers (2)

Trinh Hieu
Trinh Hieu

Reputation: 805

Create a .htaccess file in your Codeigniter project directory myproject/.htaccess and add the following code to the .htaccess file

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]

Upvotes: 0

Pradeep
Pradeep

Reputation: 9707

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

Upvotes: 22

Related Questions