由于.htaccess错误引发500错误

时间:2012-12-20 03:30:26

标签: php .htaccess codeigniter

  

可能重复:
  .htaccess throws a 500 error

我正在使用CodeIgniter,需要删除URL中的“index.php”。 我从CI教程中复制了.htaccess文件,清空了$ config ['index_page'] =''; 并将.htaccess放在根目录中。

  • 没有.htaccess文件,它运行正常,但很难看:www.example.com/index.php/site/home
  • 由于某种原因,它无法正常工作,只会引发500的错误。
  • 在日志中有一行在每次尝试中重复:[Thu 12月20日04:01:13 2012] [提醒] [客户2.55.118.161] /home/morro1980/data/www/knight-guard.org/.htaccess: 指令需要额外的参数。
  • mod_rewrite已安装并正常工作

错误在哪里,我该如何解决?

提前谢谢

我的.htaccess文件:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    #Removes access to the system folders by users.
    #Additionly this will allow you to create a System.php controller,
    #previously this would not have not 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>

我的网站控制器:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Site extends CI_Controller {
    public function index(){
        $this->home();
    }
    public function home(){
        echo "default function started.<br/>";
        $this->hello();
        $data['title'] = 'Home!';
        $data['name'] = 'Ilia';
        $data['fname'] = 'Lev';
        $data['operation'] = 'minus';
        $data['val1'] = 5;
        $data['val2'] = 7;
        echo $data['operation']."<br/>";
        $data['result'] = $this->math($data);
        $this->viewLoad("home_view", $data);
        echo "<br/>";
    }
    public function hello(){
        echo "hello function started.<br/>";
    }
    public function math($data){
        $operation = $data['operation'];
        $val1 = $data['val1'];
        $val2 = $data['val2'];
        $this->load->model("math");
        return $this->math->calculate($operation, $val1, $val2)."<br/>";
    }
    public function viewLoad($whatToView, $data){
        try{
            $this->load->view($whatToView, $data);
        }catch(Exception $e){
            echo "There is no such view";
        }
    }
    public function about(){
        $data['title'] = "About!";
        $this->viewLoad("about_view",$data);
    }
}

2 个答案:

答案 0 :(得分:1)

确保您的.htaccess中有<IfModule></IfModule>匹配。

答案 1 :(得分:1)

第一个<ifModule>没有关闭,这个:

RewriteRule ^(.*)$ index.php?/$1 [L]
<IfModule>

必须是

RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
#^