Reputation: 123
my view is :-
<li class="">
<a class="" href="<?php echo base_url(); ?>Login">
<i class="fa fa-unlock-alt"></i> 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
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
Reputation: 2175
I changed from $route['login'] = ['login/index']; to $route['login'] = 'login/index'; in my case.
Upvotes: 0
Reputation: 2059
You have to use 3 more steps:
.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]
*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'] = '';
<li>
<a href="<?php echo base_url('login'); ?>">
<i class="fa fa-unlock-alt"></i> Login </a>
</li>
I think it will work. :)
Upvotes: 6
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> Login </a>
</li>
Upvotes: 0
Reputation: 502
Try site_url()
in place of base_url()
<a class="" href="<?php echo site_url(); ?>Login">
Upvotes: 0