Search code examples
codeignitercodeigniter-3

Codeigniter URI routing not working 404 error


my view is :-

<li class="">
  <a class="" href="<?php echo base_url(); ?>Login"> 
  <i class="fa fa-unlock-alt"></i>&nbsp;Login </a>
</li>

my Login Controler

class Login extends CI_Controller {
    public function __construct(){
        parent::__construct();
    }
    public function index()
    {
         $this->load->view('login');
    }
}

When i clicked on link it says 404 page not found. but when edit the link manually and write /index.php/Login it is working fine. how to fix this...


Solution

  • You have to use 3 more steps:

    1. create a .htaccess file on project root(on your project folder "/project" or domain root directory)

    Insert following line of codes on .htaccess file.

    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} !-f

    RewriteCond %{REQUEST_FILENAME} !-d

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

    1. Find config/congig.php file and change this line to-

    *add base url in my case:

    $config['base_url'] = 'http://localhost/cirest.dev/'; ( assign your project path/URL)

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

    1. ADD this HTML to your view:

    <li>

    <a href="<?php echo base_url('login'); ?>">

    <i class="fa fa-unlock-alt"></i>&nbsp;Login </a>

    </li>

    I think it will work. :)