【问题标题】:Codeigniter htaccess not working in ubuntu 16.04Codeigniter htaccess 在 ubuntu 16.04 中不起作用
【发布时间】:2018-07-04 11:19:17
【问题描述】:

此应用程序在 Codeigniter 版本 = 3.1.3 中构建。在构建此应用程序时,可以使用此 htaccess 文件正常工作,但今天当我运行此应用程序并遇到此类错误时。

运行我的 codeigniter 网站时,htaccess 文件无法重写我的 index.php 网址。因此,显示未找到请求的 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>

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

【问题讨论】:

  • 你得到的错误是什么?
  • 在此服务器上找不到请求的 URL /Magpie/Front_master/aboutus.html。
  • 也显示你的代码
  • 你可能在 apache.conf 文件中需要这个“AllowOverride All”
  • sudo a2enmod rewrite 试试这个命令并重启你的 apache

标签: .htaccess ubuntu-16.04 codeigniter-3


【解决方案1】:

使用这个 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>

第 2 步:

删除 codeigniter 配置中的 index.php

$config['index_page'] = '';

第 3 步:

允许在 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

并使用此网址:

localhost/Magpie/Front_master/aboutus

【讨论】:

  • 不工作。同样的问题
  • 你用的是什么网址?
  • localhost/Magpie/Front_master/aboutus
  • 你改过 $config['index_page'] = "";在 config.php 中?
  • $config['base_url'] 不应为空。正如它在 config.php 中此设置的 cmets 中所述“警告:您必须设置此值!”
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-12-23
  • 1970-01-01
  • 2018-11-09
  • 1970-01-01
  • 1970-01-01
  • 2018-07-29
相关资源
最近更新 更多