Codeigniter Htaccess and URL Redirect issues
12,515
This simple .htaccess will remove your index.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Change your check function like this
public function check(){
$this->load->model('check');
$logcheck = $this->check->check($this->input->post('username'),$this->input->post('password'));
if($logcheck == "admin"){
//may be you need to set login credential into session
redirect('Phonebook/home/');
//$this->load->view('home');
}else{
$this->load->view('login');
}
}
and your home function will be like this
public function home(){
//remember you need to check login validation from session
$this->load->view('home');
}
to use redirect
function remember you have url
helper loaded.
May be this help you
Author by
magicianiam
im reb a web developer knowledgable in php, css, html, and mysql.
Updated on July 01, 2022Comments
-
magicianiam almost 2 years
I am trying to use
.htaccess
on CodeIgniter, but it is not working.I have already set:
AllowOverride All
$config['index_page'] = ''; $config['uri_protocol'] = 'REQUEST_URI';
I am using XAMPP on Windows.
My
.htaccess
:RewriteEngine On RewriteCond $1 !^(index\.php|images|scripts|css|robots\.txt) RewriteRule ^(.*)$ /index.php/$1 [L]
My URL still contains
index.php
and, if I try to remove it manually, it returns a 404 errorAlso my other concern is my login page: whenever I login, my URL is stuck on the check page.
I was wondering how do I rewrite my URL to change to home page instead of staying on the check page.
public function check(){ $this->load->model('check'); $logcheck = $this->check->check($this->input->post('username'),$this->input->post('password')); if($logcheck == "admin"){ $this->load->view('home'); }else{ $this->load->view('login'); } }