-1

I have this code and I want to add a stylesheet file to my page in my CI project. I have set the config file to

$config['base_url'] = 'localhost/project/';

However, the link that tries to get this file includes index.php and in return I cannot link the stylesheet. What is wrong with my code?

<link href="../<?php base_url();?>vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">

When I echo the base url it shows localhost/project/.

This is the error: GET http://localhost/project/index.php/vendor/bootstrap/css/bootstrap.min.css 404 (Not Found)

Spy
  • 149
  • 10

2 Answers2

1

$config['base_url'] needs a full URL complete with protocol. Try this.

$config['base_url'] = 'http://localhost/project/';

If you're using ssl then the protocol should be https://

DFriend
  • 8,869
  • 1
  • 13
  • 26
0

As a very advanced solution to your Question

1- You have to set your .htaccess file to:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

2- set your config.php file in config folder to:

$url = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "https" : "http");
$url .= "://".$_SERVER['HTTP_HOST'];
$url .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);

$config['base_url'] = $url;

and

$config['index_page'] = '';

With this trick, you even don't need to set $config['base_url'] manually :)