Part 1 Setting up the project Code Igniter and Twitter Bootstrap

Codeigniter HMVC

In this tutorial, I will show you how I set up the project folder with Code Igniter and Twitter bootstrap framework. The different configuration that I make for clean URLs and have the basic pages running.

So, what’s the starting point? Well, I have downloaded the Code Igniter framework zip file from the site and extracted it. Yes, I don’t want the user_guide folder so I removed that. Also, I have downloaded the Twitter Bootstrap CSS framework and added the CSS, JS and Images folder.

Once that is done, it’s time to add the .htaccess file in the root folder. This is a crucial part of having clean URLs inside CodeIgniter. If not done, all your pages will have index.php as part of the URL which no one wants. The .htaccess file is a straight copy paste from the Boilerplate framework which has all the goodies inside it pre-configured. You can find that at the Boilerplate site or you can also get that with the Github code link which I have provided.

After adding all these, here is a snapshot of the folder structure for my project:

Codeigniter HMVC

Feel free to refer to the Github link where you can find all the files.

Configure clean URL for Code Igniter

So, the next step is to setup clean URL and also have a dynamic base path so that we don’t have to configure it again and again when we change the directory or move our installation to the production server.

Inside the the .htaccess file the only thing you will need to change is line number 547 RewriteBase /learningci and then inside the config/config.php file I add this piece of code to configure the base_url:

$root = "http://".$_SERVER['HTTP_HOST'];
$root .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
$config['base_url'] = $root;

After this, the other thing that you need to do it remove “index.php” form the $config$’index_page'[. Once you do this, you can see that you can access the welcome page of Code Igniter without index.php in the url. For me the url is: http://localhost/learningci/welcome

Git hub code link: