John Geliberte John Geliberte - 3 months ago 10
Linux Question

Codeigniter does not get the other controller except for the index only

Hi im currently working on a project that uses codeigniter and im having a problem with the setup in linux (ubuntu 14.04), this project is setup on a Windows machine and is now being transfered on a linux machine.

the problem is when i go to the default page of the site which is http://localhost/ it goes to my index (this is workign correctly) but when i go to the other functions in my controller it always gives 404 NOT FOUND.

(404 NOT FOUND) The requested URL /lin was not found on this server.


here is the sample of the code

class Lin extends CI_Controller {

public function index() {
$data['main_content'] = 'login_form';
$this->load->view('includes/template', $data);
}

public function validate_credentials() {
var_dump("TEST");
exit;

}


if i go to http://localhost/lin/validate_credentials it my display the TEST dump and exit but it give the 404 ERROR.

Thanks in advance.

Answer

Did you already try

http://localhost/index.php/lin/validate_credentials

Sorry I'm not so sure about which is first I'll correct it.

But if it still doesn't work. There might be something wrong with your .htaccess

Make a file called '.htaccess' in your root directory, yes with a dot in the beginning and inside is this code. When I use this, i generate clean url's without the index.php

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /PUT YOUR ROOT FOLDER NAME HERE , DON'T REMOVE THE SLASH
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php/$l [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond $1 !^(index\.php|images|robots\.txt|css)
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    ErrorDocument 404 / index.php
</IfModule>

I'm sorry if I can't eplxain this line by line, but I always put this in codeigniter and works perfectly, the just change the RewriteBase, you can search on the internet or in here stackoverflow what it meants.

Comments