【问题标题】:page redirect issue codeigniter : 404 error页面重定向问题codeigniter:404错误
【发布时间】:2019-06-17 11:09:02
【问题描述】:

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

当我输入正确的电子邮件和密码时,我应该被重定向到仪表板,但我得到了这个重定向:/auth/login 并显示

我可以澄清一下,我允许 mod_rewrite ,添加了 write 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');
}

谁能帮忙?

【问题讨论】:

  • 控制器中是否有名为 Dashboard.php 的索引函数?
  • 是的,我有索引
  • 错误提示page you requested is missing,您的仪表板控制器代码在哪里?
  • 我有一个名为 controller 的文件夹,仪表板控制器位于其中,auth 也是身份验证控制器,登录只是一个功能,所以当我按下登录时,它必须将我重定向到仪表板而不是 auth\登录(我提到作为应用程序的默认控制器

标签: php codeigniter redirect


【解决方案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';

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

redirect(base_url('dashboard'));

检查 http.conf 是否允许覆盖您的域?

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

【讨论】:

  • 用这个替换你在 .htaccess 中的内容就可以了!
  • 我更换了它,但没有机会! ://
  • 我应该用 allow 代替 deny &lt;IfModule authz_core_module&gt; Require all denied &lt;/IfModule&gt; &lt;IfModule !authz_core_module&gt; Deny from all &lt;/IfModule&gt;
  • 我再次进行了更改。尝试一下。重定向到仪表板时的完整网址是什么?
  • 这里是我重定向时的完整 URL:127.0.0.1:8000/stock-v2/auth/login 并且 auth 是默认控制器
【解决方案2】:

您必须配置您的基本 URL。

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

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

否则(现场)

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

【讨论】:

    猜你喜欢
    • 2013-08-31
    • 1970-01-01
    • 1970-01-01
    • 2023-03-27
    • 2018-10-14
    • 2011-01-19
    • 2013-05-05
    • 2014-06-12
    • 2013-06-09
    相关资源
    最近更新 更多