codeigniterfont-facefont-awesomecodeigniter-urlcodeigniter-routing

how do i load codeigniter font awesome fontface url from outside of webroot?


I just started using codeigniter and have got it setup so that it does not require index.php as part of the URL.

However, I noticed that the reference to font-awesome is not working correctly. The following is loading fine.

  <link href="assets/plugins/font-awesome/css/font-awesome.css" rel="stylesheet" type="text/css" />

However, the font .eot, woff, etc... is not found and causing the icon to appear as a 404.

@font-face {
  font-family: 'FontAwesome';
  src: url('../fonts/fontawesome-webfont.eot?v=4.2.0');
  src: url('../fonts/fontawesome-webfont.eot?#iefix&v=4.2.0') format('embedded-opentype'), url('../fonts/fontawesome-webfont.woff?v=4.2.0') format('woff'), url('../fonts/fontawesome-webfont.ttf?v=4.2.0') format('truetype'), url('../fonts/fontawesome-webfont.svg?v=4.2.0#fontawesomeregular') format('svg');
  font-weight: normal;
  font-style: normal;
}

My config:

$config['base_url'] = '';

My .htaccess:

RewriteEngine on
RewriteCond $1 !^(index\.php|css|woff|eot|ttf|svg|css|js|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

Any help is appreciated.

edit the folder structure i have is:

codeigniter/
-->application/
-->assets/
---->plugins
---->plugins/font-awesome
---->plugins/font-awesome/css
---->plugins/font-awesome/fonts
-->system/
-->.htaccess
-->index.php

Solution

  • Set your BaseUrl to you site url in config.php file like this

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

    or add this code to your config.php file

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

    this works for me 100% ;)

    reference here