file paths are wrong

ok im creating the template for my website.

I have a template folder in the views folder called SocialCrab.

in there i have a index.php file, a style.css file, and an images folder that contains the logo image.

I cant reference either the stylesheet or the logo image are these urls wrong

<link rel="stylesheet" type="text/css" href="style.css" />


<a href="#"><img src="images/logo.png" alt="logo" border="0"/></a>

neither files will load in the browser

References in images, stylesheets, anchors, etc are relative to the URL.

So in the above example, if your URL is, the browser will try to load Which probably doesn't exit.

Don't use relative paths, use absolute paths using base_url().

could u give me an example?

A bit of searching would have provided plenty of answers...

I have all site assets (stylesheets, javascript, images, etc) in a subdirectory called assets:
&lt;link rel="stylesheet" href="&lt;?php echo base_url();?&gt;assets/css/style.css" type="text/css" media="screen" /&gt;

This assumes your css files are in the directory 'assets/css' (where 'assets' is a subdirectory of the directory where your index.php is). Also, don't forget to update your .htaccess so it doesn't rewrite requests to files in the 'assets' directory.

how would i do the .htaccess part. i dont work with it much and i ahve tried googling it

I suggest you use the absolute path. Your code will be cleaner and you'll save unnecessary function calls. Assuming your app assets folder is located under public_html:

&lt;link rel="stylesheet" href="/assets/css/style.css" type="text/css" media="screen" /&gt;

It is hardly ever a good idea in programming to hard-code something. And this is not an exception. As soon as you have to move things around, you'll have a major change on your hands.

This is my .htaccess:
<IfModule mod_rewrite.c>

    # ATTENTION: if this .htaccess doesn't work, check if rewrites
    # are allowed in httpd.conf. You need to specify:
    # <Directory "my-website-directory-here">
    #     Options +FollowSymLinks
    #     AllowOverride FileInfo
    # </Directory>
    # or have these options defined globally in your httpd.conf file
    # to allow a .htaccess with rewrite rules to work!

    # activate URL rewriting
    RewriteEngine On

    # if ExiteCMS is installed in a sub-directory of the document
    # root, modify the path below accordingly
    RewriteBase /

    # nasty hack to capture ruined URI's by a mod_rewrite bug.
    # You need these two lines when you use mod_vhost_alias, and this
    # .htaccess file generates a "500 internal server error".
    # In the rule below, replace --DOCROOT-- by your full docroot path,
    # without a leading slash, but with a trailing slash!
    # (i.e 'path/to/my/docroot/', without quotes offcourse)
#    RewriteCond $1 index\.php/$
#    RewriteRule ^--DOCROOT--(.*)$ /$1 [S=1]

    # do not rewrite links to website assets
    RewriteCond $1 !^assets

    # do not rewrite for php files in the document root or robots.txt
    RewriteCond $1 !^([^\..]+\.php|robot\.txt)

    # do not rewrite requests for the standard asset files
    RewriteCond $1 !\.(css|js|png|jpg|gif|zip|gz|htc)$

    # but rewrite everything else
    RewriteRule ^(.*)$ index.php/$1 [L]


<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Thanks to Elliot Haughin

    ErrorDocument 404 /index.php


shouldnt this line do what i need it to do?

# do not rewrite requests for the standard asset files
    RewriteCond $1 !\.(css|js|png|jpg|gif|zip|gz|htc)$

If that's all you need to exclude from rewriting, yes.

For me, the condition filtering assets requests is the most important one. I need this only when running the setup (because there are no assets yet).
By centralizing your assets in one directory, you also don't have to think about modifying your .htaccess when you introduce a new file type.

This is important when you move the rules to httpd.conf (using .htaccess is expensive), you don't want to have to restart the (production) webserver if it isn't absolutely needed.

I agree with Wanwizard: it's just good practice to build a system that will continue to work even if you add new stuff!
So using /assets (of however you like to call it) is better than switching by file type.

Also, don't forget you will still have to use complete paths in your view! If you try to load "assets/img/myimage.png" from a view, it will likely not work, unless you happen to be on the home page. Because the browser will request the file relative to the current location. See Wanwizard's first comment.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.