PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, March 15, 2022

[FIXED] Codeigniter URI routing not working 404 error

 March 15, 2022     codeigniter, codeigniter-3     No comments   

Issue

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



Answered By - Rashedul Islam Sagor
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing