irish
irish

Reputation: 39

Only default controller is working and the rest is 404 not found

I'm using codeigniter on my wamp and everything is fine but when I upload it on live server the default_controller is working but the other controller are 404 not found or "The requested URL /Sample_controller was not found on this server".

Here is my sample controller:

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

    class Sample_controller extends CI_Controller {
        function __construct(){
            parent::__construct();
    }

    public function index(){
        print_r('Hello World');
    }
}

and here's my config.php:

$config['base_url'] = 'http://'.$_SERVER['HTTP_HOST'].'/';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
$config['enable_query_strings'] = FALSE;
$config['controller_trigger'] = 'c';
$config['function_trigger'] = 'm';
$config['directory_trigger'] = 'd';
$config['allow_get_array'] = TRUE;

and this is my router.php:

$route['default_controller']    = 'login';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;

and my .htaccess:

<IfModule mod_rewrite.c>
    Options +FollowSymLinks
    Options +Indexes
    RewriteEngine On

    RewriteBase /folder
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{HTTP_HOST} !www.sampleurl.com$ [NC]
    RewriteCond %{REQUEST_URI} ^/$


    RewriteCond $1 !^(index\.php|assets|user_assets|tmp|robots\.txt)
    RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>

if I tried this sampleurl.com it's working fine and will direct me to my default controller which is the login but if i tried this sampleurl.com/sample_controller or sampleurl.com/login it will lead me to 404 not found The requested URL /sample_controller was not found on this server. Apache/2.4.7 (Ubuntu) Server at sampleurl.com Port 80

I hope someone can help me on this I tried changing them to:

$config['uri_protocol'] = AUTO
$config['enable_query_strings'] = TRUE;

and it's still not working.

Upvotes: 1

Views: 1342

Answers (3)

Cody
Cody

Reputation: 101

Just simply change

RewriteBase /folder

This line of code in your .htaccess file to appropriate folder name of your project and it will work fine.

Upvotes: 1

Muhammad Furqan Ul Haq
Muhammad Furqan Ul Haq

Reputation: 170

According to your code, you may have these 2 issues:
1- As per documentation you are required to make your controller filename first character Uppercase.
2- Try adding a question mark "?" in your .htaccess file's last rule. Also remove the "/" before "index.php" check the code below.

Current code:

RewriteRule ^(.*)$ /index.php/$1 [L]


New code:

RewriteRule ^(.*)$ index.php?/$1 [L]

Upvotes: 1

shauns2007
shauns2007

Reputation: 128

You need to add a route for that controller to work

$route['sample_controller']    = 'sample_controller';

For every new controller you create you need to have a route for it

Upvotes: 1

Related Questions