且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

codeigniter的.htaccess和URL重定向问题

更新时间:2023-09-12 08:06:58

这个简单的.htaccess将删除你的index.php

  RewriteEngine叙述上
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则^(。*)$的index.php / $ 1 [L]
 

更改您的检查功能像这样

 公共功能检查(){
    $这个 - >负载>模型('检查');
    $ Logcheck的= $this->check->check($this->input->post('username'),$this->input->post('password'));

    如果($ Logcheck的==管理员){
        //可能是你需要设置的登录凭证进入会议
        重定向(电话簿/家居/');
        // $这个 - >负载>查看(家);
    }其他{
        $这个 - >负载>查看('登录');
    }
}
 

和您的家庭功能​​会是这样

 公共职能的家(){
      //记住,你需要检查的会话登录验证
      $这个 - >负载>查看(家);
}
 

使用重定向功能还记得你有网​​址帮手加载。
可能是这个帮助你

I am trying to use .htaccess on CodeIgniter, but it is not working.

I have already set:

AllowOverride All

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

I am using XAMPP on Windows.

My .htaccess:

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

My URL still contains index.php and, if I try to remove it manually, it returns a 404 error

Also my other concern is my login page: whenever I login, my URL is stuck on the check page.

I was wondering how do I rewrite my URL to change to home page instead of staying on the check page.

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

This simple .htaccess will remove your index.php

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

Change your check function like this

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

and your home function will be like this

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

to use redirect function remember you have url helper loaded.
May be this help you