php – Codeigniter Htaccess和URL重定向问题

前端之家收集整理的这篇文章主要介绍了php – Codeigniter Htaccess和URL重定向问题前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图在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.可能对你有所帮助

猜你在找的PHP相关文章