.htaccessubuntu-16.04codeigniter-3

Codeigniter htaccess not working in ubuntu 16.04


This application biuld in Codeigniter Version = 3.1.3. when build this application work it properly with this htaccess file but today when i run this application & face this type of error.

When run my codeigniter website, htaccess file can't rewrite my index.php url. so, requested URL was not found error shown.

properly working url => localhost/Magpie/index.php/Front_master/aboutus.html

Error url => localhost/Magpie/index.php/Front_master/aboutus.html


Here is my htaccess code:

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

Controller file: 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


Solution

  • Use this htaccess code

    <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>
    

    Step 2 :

    Remove index.php in codeigniter config

    $config['index_page'] = '';
    

    Step 3 :

    Allow overriding htaccess in Apache Configuration (Command)

    sudo nano /etc/apache2/apache2.conf
    

    and edit the file & change to

    AllowOverride All
    

    for www folder

    Step 4 :

    Enabled apache mod rewrite (Command)

    sudo a2enmod rewrite
    

    Step 5 :

    Restart Apache (Command)

    sudo /etc/init.d/apache2 restart
    

    and use this url:

    localhost/Magpie/Front_master/aboutus