加入收藏 | 设为首页 | 会员中心 | 我要投稿 安卓应用网 (https://www.0791zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > PHP > 正文

php – Codeigniter Htaccess和URL重定向问题

发布时间:2020-05-25 08:48:52 所属栏目:PHP 来源:互联网
导读:我试图在CodeIgniter上使用.htaccess,但它无法正常工作. 我已经设定: AllowOverride All $config[index_page] = ;$config[uri_protocol] = REQUEST_URI; 我在Windows上使用XAMPP. 我的.htaccess: RewriteEngine OnRewriteCond $1 !^(i

我试图在CodeIgniter上使用.htaccess,但它无法正常工作.

我已经设定:

AllowOverride All
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';

我在Windows上使用XAMPP.

我的.htaccess:

RewriteEngine On
RewriteCond $1 !^(index.php|images|scripts|css|robots.txt)
RewriteRule ^(.*)$/index.php/$1 [L]

我的URL仍包含index.php,如果我尝试手动删除它,则会返回404错误

另外我的另一个问题是我的登录页面:每当我登录时,我的URL都会卡在检查页面上.

我想知道如何重写我的URL以更改为主页而不是留在检查页面.

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');
        }
    }
这个简单的.htaccess将删除你的index.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$index.php/$1 [L]

像这样更改您的支票功能

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');
    }
}

你的家庭功能将是这样的

public function home(){
      //remember you need to check login validation from session
      $this->load->view('home');
}

使用重定向功能记得你已经加载了url helper.可能对你有所帮助

(编辑:安卓应用网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读