Codeigniter 2: The requested URL was not found on this server error (404). CI does not follow the right path

advertisements

This is one of the most repeated questions, but I did not get it and had to ask. I use CI 2. I removed index.php from URL by following steps:

  1. In config.php I set
$config['index_page'] = '';

$config['uri_protocol'] = 'REQUEST_URI';

  1. In routes.php I set
$route['default_controller'] = "InterviewController";

  1. here is my .htaccess
RewriteEngine on
RewriteCond $1 !^(index\.php|img|robots\.txt|css|js|libraries/ckeditor|upload)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
addDefaultCharset UTF-8

  1. I enabled mod_rewrite on the web server.

So in the index() method of InterviewController, I load the addInterview.php view. After that, it is being called addInterview as the default page of the site when I type just the domain name. Problem occurs when I press Save button on addInterview page which must call saveInterview() from InterviewController. But in this step I get The requested URL was not found on this server (404) error. saveInterview() even hasn't been called. But if I myself type domainname/index.php/InterviewController/saveInterview everything works. Seems like I removed index.php just from default page, but not from all pages of my site. What do you recommend?


The leading slash could be causing your problem.

Change

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

to

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