0
votes

My header.php doesn't link to default.css properly. Page loads without CSS applied. If I view the source of the page and click on the link to .css file - 403 Forbidden shows up in Source View.

config.php

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

routes.php

$route['default_controller'] = "page/view";
$route['404_override'] = '';

pages is the controller

view is the method

application/view/templates/header.php

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <link href="<?php echo base_url(); ?>application/css/default.css" rel="stylesheet" type="text/css" />
        <title><?php echo $title; ?></title>
    </head>
    <body>

application/css/default.css

* {margin:0;padding:0;}

body {
    background-image: url(../images/bg.gif);
    background-repeat: repeat-x;
    ...
}

application/images/

-- bg.gif GIF Image 1KB

3
403 Forbidden -> check the error log of your webserver. It should tell you more what's going on behind the scenes - hakre
use href="/application/css/default.css" - JvdBerg

3 Answers

1
votes

Is a good practice to put css files in "assets" directory instead of "application". Move the file to a directory called assets/css in your DOCUMENT_ROOT and change this line:

<link href="<?php echo base_url(); ?>application/css/default.css" rel="stylesheet" type="text/css" />

to:

<link href="<?php echo base_url(); ?>assets/css/default.css" rel="stylesheet" type="text/css" />
0
votes

This is the default state of Codeigniter. You need to create a .htaccess file in your css and image directory and put this code (it should work, I am using it):

allow from All

Or you can create a public folder in the root folder and not have this problems.

0
votes

Leave base_url in config blank.Like this:

  $config['base_url'] = '';