redirect the current controller after login
<p>when I'm logged in my system and my current url is like this 
<code>localhost/storeLTE/login</code>/ it works fine, but after I'm logged and I have <code>localhost/storeLTE/home</code>. however if I write <code>localhost/storeLTE/</code> redirect me to my login and I have to login again.how can I do it when I write <code>localhost/storeLTE/</code> redirect me to my home instead of login.  I need to direct to the current controller after I'm logged for instance. </p>

<ol>
<li><p>load view login</p></li>
<li><p>login in </p></li>
<li>get the access</li>
<li>load home view</li>
<li>I want  to write <code>localhost/storeLTE/</code> after i get home access to test if I stay in home access even if I request login view redirect to home</li>
<li>stay home view</li>
<li>request loggout</li>
<li>load view login</li>
</ol>

<p>Login controller.</p>

<p>

<pre><code>class Login extends MY_Controller {
    public function __construct(){
        parent::__construct();
        $this-&gt;load-&gt;model('User_model');
    }

    public function index(){
        $data['module'] = 'Login';
        $this-&gt;load-&gt;view('login',$data);
    }

    public function getAccess(){
        $username = $this-&gt;security-&gt;xss_clean($this-&gt;input-&gt;post('username'));
        $password = $this-&gt;security-&gt;xss_clean($this-&gt;input-&gt;post('password'));
        $array = $this-&gt;User_model-&gt;login($username,$password);
        if($array[0] == 0){
            echo 0;
        }else{
            $data_session = array(
                'id' =&gt; $array[0]['id'],
                'username' =&gt; $array[0]['usuario'],
                'password' =&gt; $array[0]['password'],
                'name' =&gt; $array[0]['nombre'],
                'last_name' =&gt; $array[0]['apellido'],
                'type' =&gt; $array[0]['id_perfil'],
                'logged_in' =&gt; TRUE
            );
            $this-&gt;session-&gt;set_userdata('log',$data_session);
        }
    } 

    public function logout(){
        $this-&gt;session-&gt;sess_destroy();
        redirect('login');
    }
}
</code></pre>

<p>My_controller</p>

<pre><code>&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class MY_Controller extends CI_Controller {

    function __construct(){
        parent::__construct();
    }

    protected function isLogged(){
        if(!$this-&gt;session-&gt;userdata('log'))
            redirect('login');
    }
}

/* End of file MY_Controller.php */
/* Location: ./application/controllers/MY_Controller.php */
</code></pre>

<p>home controller </p>

<pre><code>&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Home extends MY_Controller {

    public function __construct(){
        parent::__construct();
        $this-&gt;isLogged();
    }

    public function index(){
        $data = $this-&gt;session-&gt;userdata('log');
        $data['module']  = "Home";
        $this-&gt;load-&gt;view('header',$data);
        $this-&gt;load-&gt;view('home');
    }

}

/* End of file Welcome.php */
/* Location: ./application/controllers/Welcome.php */
</code></pre>

<p>route config</p>

<pre><code>&lt;?php
defined('BASEPATH') OR exit('No direct script access allowed');

/*
| -------------------------------------------------------------------------
| URI ROUTING
| -------------------------------------------------------------------------
| This file lets you re-map URI requests to specific controller functions.
|
| Typically there is a one-to-one relationship between a URL string
| and its corresponding controller class/method. The segments in a
| URL normally follow this pattern:
|
|   example.com/class/method/id/
|
| In some instances, however, you may want to remap this relationship
| so that a different class/function is called than the one
| corresponding to the URL.
|
| Please see the user guide for complete details:
|
|   https://codeigniter.com/user_guide/general/routing.html
|
| -------------------------------------------------------------------------
| RESERVED ROUTES
| -------------------------------------------------------------------------
|
| There are three reserved routes:
|
|   $route['default_controller'] = 'welcome';
|
| This route indicates which controller class should be loaded if the
| URI contains no data. In the above example, the "welcome" class
| would be loaded.
|
|   $route['404_override'] = 'errors/page_missing';
|
| This route will tell the Router which controller/method to use if those
| provided in the URL cannot be matched to a valid route.
|
|   $route['translate_uri_dashes'] = FALSE;
|
| This is not exactly a route, but allows you to automatically route
| controller and method names that contain dashes. '-' isn't a valid
| class or method name character, so it requires translation.
| When you set this option to TRUE, it will replace ALL dashes in the
| controller and method URI segments.
|
| Examples: my-controller/index -&gt; my_controller/index
|       my-controller/my-method -&gt; my_controller/my_method
*/
$route['default_controller'] = 'login';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
</code></pre>