php - Codeigniter Htaccess 和 URL 重定向问题

标签 php apache .htaccess codeigniter mod-rewrite

我正在尝试在 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');
}

要使用 redirect 函数,请记住您已加载 url 帮助程序。
也许这对你有帮助

关于php - Codeigniter Htaccess 和 URL 重定向问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28517126/

相关文章:

php - 如何获取正在电影院播放的所有电影?

android - Tika 与安卓兼容吗?

.htaccess - 启用缓存 Google PageSpeed

wordpress - 我应该在 WordPress 中使用选项 - 索引吗?

php - 基于用户的子域

php - SQL执行时间太长

php - AFNetworking 代码块未被执行

PHP:搜索 "a.."

python - celery 如恶魔

java - 使用 apache common compress/org.tukaani.xz 在 java 中解码 LZMA 压缩 zip 文件的问题