Integrate Bootstrap on CodeIgniter

Integrate Bootstrap on CodeIgniter

  1. Blog
  2. 15 November 2026
  3. 2 min read

Stefan Bogdanescu

Founder & Senior Architect

Why Bootstrap Assets Disappear in CodeIgniter and How to Fix It

If you are attempting to load Bootstrap files using base_url() inside a CodeIgniter controller or view, and the browser reports that the assets cannot be found despite your path checks passing, the issue almost certainly lies in how CodeIgniter handles URL generation relative to its configuration.

The specific error manifests when the generated HTML points to application/bootstrap/css/bootstrap.min.css. While your PHP logic confirms this string is correct, the web server often refuses to serve static assets located inside the application directory. This is a fundamental architectural distinction in legacy MVC frameworks: the application folder contains application logic and views, whereas the public (or system) folder serves as the document root where static files must reside for security and routing reasons.

When you use base_url('application/bootstrap/css/bootstrap.min.css'), CodeIgniter constructs a URL that expects the file to exist at http://yoursite.com/application/bootstrap/.... However, most server configurations (Apache, Nginx) are configured to serve files only from the public directory. Attempting to access /application directly often results in a 403 Forbidden error or a redirect loop, causing the browser to fail loading the CSS and JS files entirely.

To resolve this, you must adjust your file structure and your URL generation strategy. The most robust approach involves moving your Bootstrap assets out of the application directory and into a dedicated folder within the public root, such as assets or public/bootstrap.

Here is the corrected directory structure:

project-root/
├── public/
│   ├── index.php
│   └── bootstrap/          # Move CSS and JS here
│       ├── css/
│       │   └── bootstrap.min.css
│       └── js/
│           └── bootstrap.min.js
├── application/
│   └── views/
│       └── your_view.php

Once the files are located in public/bootstrap, you need to update your view file. Instead of pointing to the application folder, point directly to the public path:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Bootstrap Integration</title>

    <!-- Corrected path pointing to public folder -->
    <link href="<?php echo base_url('bootstrap/css/bootstrap.min.css'); ?>" rel="stylesheet">
    
    <!-- jQuery is required for Bootstrap plugins -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
    
    <!-- Corrected path pointing to public folder -->
    <script src="<?php echo base_url('bootstrap/js/bootstrap.min.js'); ?>"></script>
  </head>
  <body>
      <!-- Your content here -->
  </body>
</html>

By moving the assets, you ensure that the URL generated by base_url() resolves to a location the web server is explicitly configured to serve. This separation of concerns keeps your application logic clean while adhering to standard security practices regarding static asset serving.

An alternative approach, particularly useful if refactoring the entire project structure feels intrusive, involves utilizing CodeIgniter's configuration constants. You can define base_path() in your environment configuration to dynamically determine the correct root path, though for simple asset loading, ensuring the assets reside in a subdirectory of the public folder remains the standard industry practice.

If you are managing multiple projects or need a more flexible asset management system that scales beyond simple file inclusion, consider exploring modern alternatives such as Laravel, which offers a built-in, opinionated structure for handling static assets via its public directory and package manager capabilities. For further details on leveraging similar robust frameworks for scalable web applications, you can read about Laravel at https://laravelcompany.com.

Our network