Balakumar B
Balakumar B

Reputation: 790

404 page not found error in Codeigniter

I am new to the codeigniter framework and I have tried to make my first program but received a 404 page not found error

This is my root directory Codeigniter and my directory structure

enter image description here

My source folder contains the .htaccess file containing the following code

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]

Home.php

    class  Home extends CI_Controller{
    public function index(){
        $this->load->view('View');
    }
}

view.php

echo "HI this is my first codeigniter program";

I have tried the following url http://localhost/Codeigniter/ but I get a 404 error, however http://localhost/Codeigniter/home loads the correct result even though my actual root folder is Codeigniter

how to solve this problem?

Upvotes: 1

Views: 3713

Answers (2)

Rajkumar R
Rajkumar R

Reputation: 1097

Change route file in this following path:-

CodeIgniter/application/config/routes.php

$route['default_controller'] = 'required_controller';

Then only you can access the following url

http://localhost/Codeigniter/

Upvotes: 3

user4419336
user4419336

Reputation:

Try where

RewriteRule .* index.php/$0 [PT,L] 

change to

RewriteRule .* index.php/$1 [PT,L]

.htaccess

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$1 [PT,L]

Or

Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

More htaccess here

Make sure your htaccess is outside of application folder.

And then on config.php

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

$config['index_page'] = '';

And then you can set your routes.php lower case best on routes.php

$route['default_controller'] = 'home';

Upvotes: 2

Related Questions