Second display gives 404 error on style sheet - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Second display gives 404 error on style sheet (/showthread.php?tid=49950) Pages:
1
2
|
Second display gives 404 error on style sheet - El Forum - 03-08-2012 [eluser]Ed Robindon[/eluser] I'm trying to do a simple site with an application wide template view: The view template: Code: <!DOCTYPE html> The controller: Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); The index display works fine. When I call for the about page it has no css and Firebug shows a 404 under the link tag. Any thoughts? Ed Second display gives 404 error on style sheet - El Forum - 03-08-2012 [eluser]CroNiX[/eluser] Don't use a relative path for your stylesheet, or anything else. Second display gives 404 error on style sheet - El Forum - 03-08-2012 [eluser]Ed Robindon[/eluser] Thanks, I'll try it. Still don't understand why it would work from the index function... Second display gives 404 error on style sheet - El Forum - 03-08-2012 [eluser]Aken[/eluser] Because when you use relative URLs, it adds the link to the stylesheet to the end of whatever URL you're currently looking at. So your homepage would look for a CSS file here: example.com/assets/styles/site_style.css (which is typically accurate). If you were on a different level folder, it would look for it there: example.com/anotherpage/assets/styles/site_style.css (not accurate, 404). Second display gives 404 error on style sheet - El Forum - 03-08-2012 [eluser]InsiteFX[/eluser] Code: <!DOCTYPE html> Second display gives 404 error on style sheet - El Forum - 03-08-2012 [eluser]Ed Robindon[/eluser] Thanks for the help guys. The base_url addition made everything better... Second display gives 404 error on style sheet - El Forum - 04-18-2012 [eluser]novice32[/eluser] Honestly, as a best practice I would recommend that everyone go with the latter version you presented (below). The primary reason is if you ever enable SSL for your website, you won't get a bunch of 404 errors for your asset files; this avoids having to recode your template layout and changing the src/href for each asset file (image, css, js etc). I'm doing that now. Code: <link rel='stylesheet' href='<?php echo base_url();?>assets/styles/site_style.css' /> -----see below, this won't work ---- for SSL you must use relative path Second display gives 404 error on style sheet - El Forum - 04-18-2012 [eluser]novice32[/eluser] I stand corrected! The previous won't work, because of SSL, you need to use relative path, and my home page relative would be different from my interior files, which will cause an error. Thoughts anyone on a work around? Second display gives 404 error on style sheet - El Forum - 04-18-2012 [eluser]InsiteFX[/eluser] Code: <link rel="stylesheet" href="<?php echo base_url('assets/styles/site_style.css');?>" /> Second display gives 404 error on style sheet - El Forum - 04-18-2012 [eluser]CroNiX[/eluser] Code: <link rel='stylesheet' href='/assets/styles/site_style.css' /> |