页面重定向问题codeigniter:404错误

时间:2019-06-17 11:09:02

标签: php codeigniter redirect

我正在使用CodeIgniter创建应用程序。

当我输入正确的电子邮件和密码时,我应该被重定向到仪表板,但是我得到以下重定向:/ auth / login,它显示 enter image description here

我可以澄清一下,我允许mod_rewrite,添加了写base_url并允许在apache上进行连接

我的Config.php

   $config['base_url'] = 'http://127.0.0.1:8000/stock-v2/'; 

我的控制器:

 public function login()
{

    $this->logged_in();

    $this->form_validation->set_rules('email', 'Email', 'required');
    $this->form_validation->set_rules('password', 'Password', 'required');

    if ($this->form_validation->run() == TRUE) {
        // true case
        $email_exists = $this->model_auth->check_email($this->input->post('email'));

        if($email_exists == TRUE) {
            $login = $this->model_auth->login($this->input->post('email'), $this->input->post('password'));

            if($login) {

                $logged_in_sess = array(
                    'id' => $login['id'],
                    'username'  => $login['username'],
                    'email'     => $login['email'],
                    'logged_in' => TRUE
                );

                $this->session->set_userdata($logged_in_sess);
                redirect('dashboard', 'refresh');
            }
            else {
                $this->data['errors'] = 'Incorrect username/password combination';
                $this->load->view('login', $this->data);
            }
        }
        else {
            $this->data['errors'] = 'Email does not exists';

            $this->load->view('login', $this->data);
        }   
    }
    else {
        // false case
        $this->load->view('login');
    }   
}

    */
public function logout()
{
    $this->session->sess_destroy();
    redirect('auth/login', 'refresh');
}

有人可以帮忙吗?

2 个答案:

答案 0 :(得分:1)

更改您的.htaccess文件。将此粘贴到应用目录中的.htaccess中(与应用程序处于同一级别),将起作用:

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA] 

在conf.php中:

$config['base_url'] = 'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].'/stock-v2/';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';

然后像这样使用regireg而不刷新:

redirect(base_url('dashboard'));

签入http.conf,是否允许您的域覆盖?

<Directory "/var/www">
    AllowOverride All
    # Allow open access:
    Require all granted
</Directory>

答案 1 :(得分:0)

您必须配置基本URL。

如果您在本地服务器上工作,请尝试以下操作:

$config['base_url'] = 'http://localhost/stock-v2/';

否则(实时)

$config['base_url'] = 'http://<put your domain here>';