dev dev
dev dev

Reputation: 123

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...

Upvotes: 3

Views: 12606

Answers (5)

Aritra Debsarma
Aritra Debsarma

Reputation: 121

Create a file in the webroot and name it .htaccess then type this code in it

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
</IfModule>

And in your application/config/config.php file, find this

$config ['index_page'] = '';

Upvotes: 0

Tandoh Anthony Nwi-Ackah
Tandoh Anthony Nwi-Ackah

Reputation: 2175

I changed from $route['login'] = ['login/index']; to $route['login'] = 'login/index'; in my case.

Upvotes: 0

Rashedul Islam Sagor
Rashedul Islam Sagor

Reputation: 2059

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. :)

Upvotes: 6

blues911
blues911

Reputation: 910

First of all you should properly define url in config/routes.php:

$route['login'] = 'login/index';

And then you can use this route in a template with site_url() function:

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

Upvotes: 0

Ankush Srivastava
Ankush Srivastava

Reputation: 502

Try site_url() in place of base_url()

<a class="" href="<?php echo site_url(); ?>Login">

Upvotes: 0

Related Questions