0

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

2
  • 403 Forbidden -> check the error log of your webserver. It should tell you more what's going on behind the scenes Commented Sep 30, 2012 at 17:19
  • use href="/application/css/default.css" Commented Sep 30, 2012 at 17:20

3 Answers 3

1

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" />
Sign up to request clarification or add additional context in comments.

1 Comment

i just want to add that you can include the files inside the base_url like base_url('assets/css/default.css'); which become much more readable ..
0

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.

Comments

0

Leave base_url in config blank.Like this:

  $config['base_url'] = '';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.