简体   繁体   中英

Codeigniter redirect URL issue

I am new to codeigniter. I have just made a login feature in CI with the help of google, but here I am redirecting to URL on login but It is not working. Here is the details after redirecting the link is like this http://localhost/xpensepedia/index.php/home which is giving the 404 error

404 Page Not Found
The page you requested was not found.

and my controller is

public function index() {
        $this->load->view('header');
        if (($this->session->userdata('user_id') != "")) {
            redirect(site_url('home'));
        } else {
            $this->load->view("register");
        }
    $this->load->view('footer');
}

My files are in the image 在此输入图像描述

请检查您给home.php控制器的课程名称

you can add url path on constraints .... you define the url like this on constants :

define('ROUTE_STIE_PATH','localhost/xxx'); 
define('ROUTE_STIE_PATH_LOGIN',ROUTE_STIE_PATH.'login/'); 
define('ROUTE_STIE_PATH_HOME',ROUTE_STIE_PATH.'home/');

and then you can echo by simply

echo ROUTE_STIE_PATH_LOGIN

if you want to call any methods with in home then

echo ROUTE_STIE_PATH_HOME.'methodname';

Try this...

public function index() {

    if (($this->session->userdata('user_id') != "")) {
        redirect(site_url('home'));
    } else {
        $this->load->view('header');
        $this->load->view("register");
        $this->load->view('footer');
    }

}

Home Controller :

class Home extends CI_Controller {
       Public function index {
          $this->load->view('header');
          $this->load->view("home");
          $this->load->view('footer');
       }
}

I solve similar case when I change my config file located in application>config>config.php to the following value:

$config['base_url'] = '';
$config['uri_protocol'] = 'REQUEST_URI';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM