ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

targeting images and css

November 20, 2007 12:14am

Subscribe [5]
  • #1 / Nov 20, 2007 12:14am

    jvittetoe

    29 posts

    whenever i try to view the images in my images directory, i get a 404. what am i doing wrong here? i have my structure as is…and from my css files, any background images im targeting are not showing.

  • #2 / Nov 20, 2007 12:32am

    jvittetoe

    29 posts

    from my main layout file

    <link rel="stylesheet" href="<?=base_url();?>static/css/master.css" type="text/css" media="screen"/>

    when viewing source,

    <a href="http://localhost/pr0jects/myFinance/static/css/master.css">http://localhost/pr0jects/myFinance/static/css/master.css</a>

    my directory structure, I have attempted moving the static folder inside of application, but to no avail.
    /myFinance
    -/application
    -/system
    -/static
    —/css

    my baseURL as defined in config,

    <a href="http://localhost/pr0jects/myFinance/">http://localhost/pr0jects/myFinance/</a>
  • #3 / Nov 20, 2007 3:54am

    John_Betong

    690 posts

     
    Hi jvittetoe,

    Immediately before your link statement try this:

    <?php
        echo '
    site_url() --> ' .site_url();
        echo '
    base_url() --> ' .base_url();
        echo '
    getcwd() ----> ' .getcwd();
        echo '
    link path --->'  .base_url() .'static/css/master.css';
        die;
      ?>

    Cheers,

    John_Betong
     

  • #4 / Nov 20, 2007 4:04am

    Michael Wales

    2070 posts

    is your application within the root directory on the server (htdocs, webroot, etc)? If so, you are referencing a directory name pr0jects that doesn’t exist.

    If not, possibly try altering your file structure and placing the CSS and images in within an assets folder that you can reference from root. It makes your relative URLs much simpler:

    <link rel="stylesheet" type="text/css" href="/assets/css/style.css" media="all" />
    /assets/img/thumb.jpg
  • #5 / Nov 21, 2007 1:48am

    jvittetoe

    29 posts

    site_url()—> http://localhost/pr0jects/myFinance/
    base_url()—> http://localhost/pr0jects/myFinance/
    getcwd()——> /Users/joshvittetoe/_wwwroot/pr0jects/myFinance
    link path—->http://localhost/pr0jects/myFinance/static/css/master.css

    that is what i get…

    my localhost root directory is /_wwwroot/

    inside there i have numerous folders including a projects directory which is my repository for any applications or tests that i conduct which are given their own folders inside their, like /myFinance/

    it should be to where i can have an individual css directory for an app and shouldn’t need to reside one level up, in my root.

    when i do navigate to the /pr0jects/myFi…/static/ directory, im given a 404, it seems my app is thinking im trying to call a controller, i cant even navigate to the actual css file without showing a 404.

  • #6 / Nov 21, 2007 1:54am

    Michael Wales

    2070 posts

    Sounds like you jacked up your .htaccess file. You should have a rewrite exception in there to keep requests for your static subdirectory from going to index.php.

    Similar to:

    RewriteEngine on
    RewriteCond $1 !^(index\.php|static|robots\.txt)
    RewriteRule ^(.*)$ /index.php/$1 [L]
  • #7 / Nov 21, 2007 8:11am

    John_Betong

    690 posts

    site_url()—> http://localhost/pr0jects/myFinance/
    base_url()—> http://localhost/pr0jects/myFinance/
    getcwd()——> /Users/joshvittetoe/_wwwroot/pr0jects/myFinance
    link path—->http://localhost/pr0jects/myFinance/static/css/master.css

    that is what i get…

    my localhost root directory is /_wwwroot/

    inside there i have numerous folders including a projects directory which is my repository for any applications or tests that i conduct which are given their own folders inside their, like /myFinance/

    it should be to where i can have an individual css directory for an app and shouldn’t need to reside one level up, in my root.

    when i do navigate to the /pr0jects/myFi…/static/ directory, im given a 404, it seems my app is thinking im trying to call a controller, i cant even navigate to the actual css file without showing a 404.

    Hi jvittetoe,

    What happens when you type this into your browser?

    http://localhost/pr0jects/myFinance/static/css/master.css

     

     
    If that displays your CSS file Ok then this is the magic line that I use to call a background image which resides in the same directory.

    body {background:#ffffff url(grad_green.jpg) 0 0 repeat-x; color:#000}

     

     
    I try to work from simple code/image paths that work then try other more complicated paths.

    Cheers,

    John_Betong
     

  • #8 / Nov 21, 2007 8:38am

    frankthetank

    8 posts

    Thanks! Helped me as well.

  • #9 / Nov 21, 2007 11:29pm

    jvittetoe

    29 posts

    Hi jvittetoe,

    What happens when you type this into your browser?

    http://localhost/pr0jects/myFinance/static/css/master.css

     

    i get a CI 404 error, here is what my htaccess file reads, it is located in my, localhost/projects/myFinance/ directory,  along side my application, system and static folders

    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond $1 !^(index\.php|js|images|system\/plugins|robots\.txt|css\/)
    RewriteRule ^(.*)$ index.php/$1 [L]
    </IfModule>
  • #10 / Nov 22, 2007 12:22am

    Michael Wales

    2070 posts

    Like I said, you are not making an exception for your static directory - therefore, CI is trying to find a controller named static, a method named css, and passing a paramter of master.css

    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond $1 !^(index\.php|js|images|systems\/plugins|static|robots\.txt|css\/)
    RewriteRule ^(.*)$ /index.php/$1 [L]
    </IfModule>
  • #11 / Nov 22, 2007 2:03am

    jvittetoe

    29 posts

    sweet bro, sorry i completely overlooked your original post for that fix. htaccess just confuses me, i hardly know what im doing with it.

  • #12 / Nov 29, 2007 6:32am

    metaltapimenye

    61 posts

    thx walesmd.. u make all js/css magic keep alive in CI.

    letso if i got sub directory for my css.. let say..

    /myFinance
    -/application
    -/system
    -/static
    —/css
    —-/csssub

    i got to add csssub at .htaccess files huh?

    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond $1 !^(index\.php|js|images|systems\/plugins|static|csssub|robots\.txt|css\/)
    RewriteRule ^(.*)$ /index.php/$1 [L]
    </IfModule>
  • #13 / Jul 23, 2009 11:05pm

    joe-bbb

    6 posts

    Helped me too - and I also overlooked the first post too - thanks

  • #14 / May 02, 2011 5:30am

    senjy

    5 posts

    Hi, i have the same problem, but not resolved.

    htaccess content :

    Options +FollowSymLinks
    RewriteEngine On
    RewriteCond $1 !^(index\.php|user_guide|static|images|robots\.txt)
    RewriteRule ^(.*)$ /index.php/$1 [L]

    My Static is like here

    static
      \blueprint\
        \screen.css
        \print.css
        \ie.css


    my view

    <link rel="stylesheet" href="<?php echo base_url(); ?>static/blueprint/screen.css" type="text/css" media="screen, projection"/>
    <link rel="stylesheet" href="<?php echo base_url(); ?>static/blueprint/print.css" type="text/css" media="print"/>
    <!--[if lt IE 8]><link rel="stylesheet" href="<?php echo base_url(); ?>static/blueprint/ie.css" type="text/css" media="screen, projection"/><![endif]-->

    and

    <?php
        echo '
    site_url() --> ' .site_url();
        echo '
    base_url() --> ' .base_url();
        echo '
    getcwd() ----> ' .getcwd();
        echo '
    link path --->'  .base_url() .'static/blueprint/screen.css';
        die;
      ?>

    give me this

    site_url()—> mysite.com/index.php
    base_url()—> mysite.com/
    getcwd()——> /mysite.429/clican/www
    link path—->mysite.com/static/blueprint/screen.css

    if i go to mysite.com/static/blueprint/screen.css,
    firefox display the css content

    but when i use firebug, it’s display error 404.

    I’m using CI 2.0.2 and the autoload have

    $autoload[‘helper’] = array(‘url’);

    What’s i missing ?

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases