0

i am using codeigniter 3. i have created a simple controller and when i try to access the controller am getting the 404 error.

my controller

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

        class home extends CI_Controller {

            /**
             * Index Page for this controller.
             *
             * Maps to the following URL
             *      http://example.com/index.php/welcome
             *  - or -
             *      http://example.com/index.php/welcome/index
             *  - or -
             * Since this controller is set as the default controller in
             * config/routes.php, it's displayed at http://example.com/
             *
             * So any other public methods not prefixed with an underscore will
             * map to /index.php/welcome/<method_name>
             * @see http://codeigniter.com/user_guide/general/urls.html
             */
            public function index()
            {
                echo "Working fine";
                $this->load->view('comman/header.php');
                $this->load->view('home/home.php');

            }
        }

config file

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

$config['index_page'] = 'index.php';

$config['url_suffix'] = '';

.htaccess

Options +FollowSymLinks
RewriteEngine on

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

when i try to access the app am getting 404 error.

http://localhost/annaiplan/home/

enter image description here

3
  • try the url like this:localhost/annaiplan/index.php/home Commented Nov 21, 2015 at 5:41
  • @NirajKarmick that way it works. Commented Nov 21, 2015 at 5:44
  • 1
    You can check this for removing index.php from url Commented Nov 21, 2015 at 5:54

2 Answers 2

1

first always controller file name should be 'Home' and in class its class name should be Home extends.... second you need to change default controller from routes.php path to rout.php ==== root folder/application/config/routes.php

change from $route['default_controller'] = 'welcome';to $route['default_controller'] = 'Home';

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you. this way it works. but when i try 'localhost/annaiplan/testing' then again 404 error.
you need to write like localhost/aanaiplan/index.php/yourControllerName
ya but why index.php. why is my htaccess not working.
to resolve you need to change your htaccess.php file default provided file in codeigniter has config like that we need to use index.php vote up if way i suggested works for you!! Happy Coding
0

In htaccess file

Change:

RewriteBase /annaiplan

To:

RewriteBase /

And you can also replace htaccess code with this.

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} ^system.*
RewriteCond $1 !^(index\.php|images|js|uploads|css|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.