Codeigniter htaccess在Ubuntu 16.04中无效

3
此应用程序是使用Codeigniter 3.1.3版本构建的。在构建此应用程序时,它可以正确运行此htaccess文件,但今天当我运行此应用程序时,遇到了以下类型的错误。
当运行我的Codeigniter网站时,htaccess文件无法重写我的index.php网址。因此,显示了请求的URL未找到错误。
正确工作的URL => localhost/Magpie/index.php/Front_master/aboutus.html
错误的URL => 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>

控制器文件: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);
    }
}

enter image description here


你遇到了什么错误? - Pradeep
你可能需要在apache.conf文件中添加"AllowOverride All"。 - Parth Shah
请尝试运行以下命令并重新启动您的Apache服务器:sudo a2enmod rewrite。 - Parth Shah
为什么你的URL中有“.html”扩展名? - Pradeep
对于添加 $config['url_suffix'] = '.html'; 只是 .php 的别名。 - Syed Nasrul Islam Anam
显示剩余2条评论
2个回答

9

使用此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>

步骤二:

在CodeIgniter配置中删除index.php。

$config['index_page'] = '';

步骤三:

允许在Apache配置文件中覆盖.htaccess文件(命令行)

sudo nano /etc/apache2/apache2.conf

并编辑文件,将其更改为

AllowOverride All

针对www文件夹

步骤4:

启用Apache的mod rewrite模块(命令)

sudo a2enmod rewrite

步骤 5:

重启 Apache(命令)

sudo /etc/init.d/apache2 restart

并使用此URL:

localhost/Magpie/Front_master/aboutus


不工作。同样的问题。 - Syed Nasrul Islam Anam
你使用了哪个URL? - Shubham Azad
本地主机/Magpie/Front_master/aboutus - Syed Nasrul Islam Anam
你已经在config.php中更改了$config ['index_page'] = ""; 吗? - Shubham Azad
$config ['base_url'] 不应为空。正如 config.php 中此设置的注释所述:“警告:您必须设置此值!” - DFriend

0
有时候这可能是由于数据库问题引起的。错误信息会显示为“SELECT列表中的第8个表达式不在GROUP BY子句中,并且包含非聚合列'tappo_stage_db.Ratings.rating',该列在GROUP BY子句中的列上没有函数依赖关系;这与sql_mode=only_full_group_by不兼容”。因此,您应该运行此命令。
SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接