php – Codeigniter Htaccess和URL重定向问题

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了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 – Codeigniter Htaccess和URL重定向问题全部内容,希望文章能够帮你解决php – Codeigniter Htaccess和URL重定向问题所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。