6

Routes not working and default controller showing error 404 when I am setting welcome as a default controller then all routes defined with the welcome controller working but my other routes and url not working.

$route['default_controller'] = "welcome";
$route['testRoute'] = 'welcome/test';
$route['testRoute/(:num)'] = 'welcome/test/$i';

All above routes are working with only welcome controller.

$route['default_controller'] = "login";
$route['loginMe'] = 'login/loginMe';
$route['logout'] = 'user/logout';

Showing error 404 for all controllers and functions.

Roshan Lal
  • 61
  • 1
  • 1
  • 2

2 Answers2

11

If you put index.php after domain this will work.

http://www.example.com/index.php/login/

You should remove index.php from url by replacing in config and .htaccess

replace in config.php

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

by

$config['index_page'] = '';

.htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$0 [L]
Almani
  • 185
  • 10
  • Update : `$config['index_page'] = '';` . I already had that . `my_website/index.php/my_route` tip worked. Changing .htaccess didn't do anything ( I am using xampp and just transferred my website from Linux to xampp for dev). But then, I changed the .htaccess to a cleaner version and it now shows (removed unnecessary Apache rules )`No input file specified`. – Lucifer Jun 06 '23 at 10:24
1

This is what worked for me:

  1. In config.php of config folder, use: $config['enable_query_strings'] = FALSE;
  2. Use $config['uri_protocol'] = 'AUTO';
  3. Use $config['index_page'] = '';
  4. Also remember to set your base url. Mine is: $config['base_url'] = 'http://localhost/code';
  5. Finally use the following htaccess file:

    <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /code/index.php/$1 [L] </IfModule>

NB: Remember to edit your path to index.php in the htaccess file. Hope this works for you

chobela
  • 305
  • 3
  • 5
  • +1 for Htaccess rule. when i move code to live server my htaccess is not moved and i stuck in problem of `404`. Thanks for help – TarangP Aug 26 '20 at 16:59