Codeigniter htaccess在Ubuntu 16.04中不起作用

Sye*_*nam 1 .htaccess codeigniter-3 ubuntu-16.04

该应用程序的Codeigniter版本为3.1.3。当构建此应用程序时,可以与此htaccess文件一起正常工作,但是今天当我运行此应用程序并遇到此类错误时。

当运行我的codeigniter网站时,htaccess文件无法重写我的index.php网址。因此,未显示请求的URL错误。

正常工作的URL => localhost / Magpie / index.php / Front_master / aboutus.html

错误网址 => localhost / Magpie / index.php / Front_master / aboutus.html


这是我的htaccess代码:

    <IfModule mod_rewrite.c>
      RewriteEngine on
      RewriteBase /Magpie/
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*)$ index.php/$1 [L]
    </IfModule>
Run Code Online (Sandbox Code Playgroud)

控制器文件:Front_master.php

<?php

    class Front_master extends CI_Controller {

      public $result = array();
      public function __construct() {
      parent::__construct();

      //load models
      $this->result["getContact"] = $this->GetInformation->getContact();
      $this->result["getLogo"] = $this->GetInformation->getLogo();
      $this->result["getSlide"] = $this->GetInformation->getSlide();
      $this->result["getServices"] = $this->GetInformation->getServices();
      $this->result["getContent"] = $this->GetInformation->getContent();
      $this->result["getPropertyListing"] = $this->GetInformation->getPropertyListing();
      $this->result["getBestDeal"] = $this->GetInformation->getBestDeal();
      $this->result["getTeam"] = $this->GetInformation->getTeam();
    }

    public function index() {
      $data = array();

      $data['title'] = 'Home Page';
      $data['header'] = $this->load->view('frontview/header', $this->result, TRUE);
      $data['slider'] = $this->load->view('frontview/slider', $this->result, TRUE);
      $data['dashboard'] = $this->load->view('frontview/dashboard', $this->result, TRUE);
      $data['footer'] = $this->load->view('frontview/footer', '', TRUE);
      $this->load->view('frontview/master', $data);
    }

    public function aboutus() {
      $data = array();
      $data['title'] = 'About Us';
      $data['header'] = $this->load->view('frontview/header', $this->result, TRUE);
      $data['dashboard'] = $this->load->view('frontview/about_us', $this->result, TRUE);
      $data['footer'] = $this->load->view('frontview/footer', $this->result, TRUE);
      $this->load->view('frontview/master', $data);
    }
}
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

Shu*_*zad 6

使用此htaccess代码

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /Magpie/
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
</IfModule>
Run Code Online (Sandbox Code Playgroud)

第2步 :

删除codeigniter配置中的index.php

$config['index_page'] = '';
Run Code Online (Sandbox Code Playgroud)

第三步:

允许在Apache配置中覆盖htaccess(命令)

sudo nano /etc/apache2/apache2.conf
Run Code Online (Sandbox Code Playgroud)

并编辑文件并更改为

AllowOverride All
Run Code Online (Sandbox Code Playgroud)

用于www文件夹

第四步 :

启用apache mod重写(命令)

sudo a2enmod rewrite
Run Code Online (Sandbox Code Playgroud)

步骤5:

重新启动Apache(命令)

sudo /etc/init.d/apache2 restart
Run Code Online (Sandbox Code Playgroud)

并使用以下网址:

本地主机/喜p / Front_master / aboutus