0

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]

</IfModule>

This is my home controller

class Home extends MX_Controller{
  function __construct(){
    parent::__construct();

  }

  function index($stub=""){
    $baseUrl=base_url();
    $this->load->helper("url");

      echo $this->_showHomepage();      

  }
}

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

7
  • Can you show the Home controller? Commented Feb 13, 2020 at 13:43
  • ok..i edited my question ..u can see it above Commented Feb 13, 2020 at 13:49
  • Hmm, that's the complete controller? And what's the controller's file name? Commented Feb 13, 2020 at 13:55
  • file name is home Commented Feb 13, 2020 at 13:57
  • Try upper case Commented Feb 13, 2020 at 13:58

2 Answers 2

0

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() {
        parent::__construct();
    }

    function index() {
        $this->load->view('url');
    }

}
Sign up to request clarification or add additional context in comments.

7 Comments

why have u used authentication ...is it a module name
I edited my question...i have added my .htaccess file. 1 more thing i did not get..why have u used page/page/view
because route calls your file names
if i type ...demosite/home...thn its work...but i want to show home controller only in demosite.com
what do you get when you change base_url(); to this site_url();
|
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.