Codeigniter Htaccess和URL重定向问题


Codeigniter Htaccess and URL Redirect issues

我正在尝试在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助手
这可能会帮助您

我发现,如果你去这里http://www.insiderclub.org/downloads然后点击链接"点击这里"下载htaccess zip文件夹有大约5种不同的适合htaccess 的代码点火器

不确定这个AllowOverride All在哪里发挥作用?

还有

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

制作

$config['uri_protocol'] = 'AUTO';

$config['base_url'] = 'http://localhost/yourproject/';

$config['index_page'] = '';

确保您已经配置了路由.php

主htaccess根。你不需要触摸另一个。htaccess

你会在zip中找到的第一个是这个

Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index'.php|images|robots'.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

似乎与我的examplep和codeigniter 2&3,但试试下载的。

这是htaccess zip文件夹中的第二个,为wamp等考虑更多

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]
    #When your application folder isn't in the system folder
    #This snippet prevents user access to the application folder
    #Submitted by: Fabdrol
    #Rename 'application' to your applications folder name.
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]
    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin
    ErrorDocument 404 /index.php
</IfModule>