1

I'm trying to setting up my codeigniter routing to make an authentication form for an admin panel, but the routing is not working. I'm a beginner with CodeIgniter and I think I'm missing something.

In my server I put the CodeIgniter fiels inside folder in my root directory, so it can be accessed like this:

/localhost/ci

In my config.php I set my base url and remove the index page to remove index.php:

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

Also I have edited the .htaccess to remove the index.php like CodeIgniter documentation says, so it looks like this:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

Now, my routes config file looks like this. I set my default page and a route to my Auth controller:

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

This is my Controller:

class Auth extends CI_Controller {

function __construct() {
    parent::__construct();
    // load libraries
}

function index() {
    if (! $this->ion_auth->logged_in()) {
        // redirect them to the dashboard page
        redirect(base_url('auth/login'), 'refresh');
    } else {
        // show the dashboard page
        redirect(base_url('dashboard'), 'refresh');
    }
}

function login() {
    $this->load->view('login');
}

When I enter in the web-browser http://localhost/ci/ it redirects me to http://localhost/ci/auth/login, but then a 404 Not Found error ir raised. What am I missing? I'm a bit confused at this point, thanks.

5
  • Do u have login.php page inside views folder? Commented Mar 4, 2016 at 17:18
  • I have my view in html file for the moment, so it looks like "login.html". Is that incorrect? Commented Mar 4, 2016 at 17:22
  • May be thats the pblm. try as $this->load->view('login.html'); or convert ur html file to php file Commented Mar 4, 2016 at 17:24
  • I've just tried this and I'm getting a 404 error also.. Commented Mar 4, 2016 at 17:29
  • Why not its public function? function login() { Commented Mar 4, 2016 at 20:48

1 Answer 1

1

Try changing your .htaccess from:

RewriteEngine on RewriteCond $1 !^(index\.php|images|robots\.txt) RewriteRule ^(.*)$ /index.php/$1 [L]

To

RewriteEngine on RewriteCond $1 !^(index\.php|images|robots\.txt) RewriteRule ^(.*)$ /ci/index.php/$1 [L]

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

1 Comment

This is working fine, thanks a lot! Also I was modifying the .htaccess on my application folder. Now I created one .htaccess file in my codeigniter root directory and it's working now.

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.