Home » Php » php – codeingter3 HMVC 'default_controller' is not working

php – codeingter3 HMVC 'default_controller' is not working

Posted by: admin February 25, 2020 Leave a comment


I am using CI3 HMVC in my project. Now, I am facing problem with routing. I want user to type www.demosite.com and it would automatically call my home module. I do not want to show like www.demosite.com/home. I want to show the url like www.demo.com. for this, I set default controller in application/config/routes, like this, as follows;

$route['default_controller'] = "home";

also in my content module, I added a route folder where I wrote

$route['home'] = 'home';

Here is my .htaccess

    AddType text/x-component .htc
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond $1 !(index\.php|assets/)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]


This is my home controller

class Home extends MX_Controller{
  function __construct(){


  function index($stub=""){

      echo $this->_showHomepage();      


However, when I run this. I got 404 error. What can i do to solve this problem? Thanks in advance.

How to&Answers:

HMVC it should be like that

This only takes a method no directories are allowed
so the default controller is under controllers

$route['default_controller'] = 'pages/pages/view';

$route['default_controller'] = 'pages';

index is the default method that is called.

$route['home'] = 'authentication/home/index';

$route['home'] = 'authentication/home'; 

And than you need to change your .htaccess file to match that urls

URI Routing : https://codeigniter.com/user_guide/general/routing.html#examples

Update :

(defined('BASEPATH')) OR exit('No direct script access allowed');

class Site extends MY_Controller {

    function __construct() {

    function index() {



I solved it. I moved the Home folder from Modules folder to Controller folder and then, it just started to work