![]() |
Problem with base_url() and files not loading - 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: Problem with base_url() and files not loading (/showthread.php?tid=17103) Pages:
1
2
|
Problem with base_url() and files not loading - El Forum - 03-25-2009 [eluser]copernicus[/eluser] I am using base_url() to echo out my base url in my paths and it is working. I can see the correct path in the HTML and if I copy and paste it into the browser, it will go to the correct file. The problem is that the browser doesn't seem to be loading any of my CSS, JS, or images that are using base_url() to do the path. For instance: <img src="<?php echo base_url(); ?>assets/images/logo.jpg" alt="Reporter Ads" /> Will produce this HTML: <img src="http://reportermag.com/beta/ads/adrequest/assets/images/logo.jpg" alt="Reporter Ads" /> The image file is there and works if you go to that URL but the browser doesn't seem to be loading it onto the page. Problem with base_url() and files not loading - El Forum - 03-25-2009 [eluser]jedd[/eluser] This is very likely a problem with your .htaccess file. You could post that, if the following doesn't work. You need to add in an 'assets' exclusion, so that it doesn't get interpreted (and mis-directed). Mine looks like this: Code: RewriteEngine on But the important thing is the 'assets' option, and note that you use vertical bars ( | ) to separate different directories at the root of your CI project. Problem with base_url() and files not loading - El Forum - 03-25-2009 [eluser]Bryan Seeds[/eluser] copernicus : Yeah if your resources aren't loading then it is getting 'lost' in the rewrites.. edit your .htaccess like jedd had mentioned.. mine is like this : RewriteEngine on RewriteCond $1 !^(index\.php|images|css|js|robots\.txt) RewriteRule ^(.*)$ /index.php/$1 [L] And is your base_url() output right? your base = 'http://reportermag.com/beta/ads/adrequest/' ?? -Bryan Problem with base_url() and files not loading - El Forum - 03-26-2009 [eluser]copernicus[/eluser] Still doesn't seem to be working, here is my .htaccess file: RewriteEngine On RewriteCond $1 !^(index\.php|assets|robots\.txt) RewriteRule ^(.*)$ index.php?$1 [L] The last line is because I am using QUERY_STRING And yes, my base_url is "http://reportermag.com/beta/ads/adrequest/" Problem with base_url() and files not loading - El Forum - 03-27-2009 [eluser]jedd[/eluser] Does it work if you turn query_string off? (I've not played with it.) Have you confirmed mod_rewrite is loaded okay in Apache ( do a phpinfo() page to confirm ). Have you done an 'echo base_url()' for debugging purposes to make sure it's set to what you think it is set to. Are you assuming that echoing the string 'uri/path/file.jpg' will somehow make a picture appear, or do you have this wrapped up in img src tags? Please post a few lines around the previously posted line of your web-page source (from your browser's point of view) again. You may want to look at the img() function that comes with the the [url="http://ellislab.com/codeigniter/user-guide/helpers/html_helper.html"]HTML Helper[/url]. Problem with base_url() and files not loading - El Forum - 03-29-2009 [eluser]copernicus[/eluser] mod_rewrite is ok, the problem seems to be with something that is using the 'src' attribute. For instance, loading a CSS file like this: Code: <link type="text/css" rel="stylesheet" media="screen" href="<?php echo base_url(); ?>assets/css/reset.css" /> will work but trying to load a JS file or image file like this: Code: <img src="<?php echo base_url(); ?>assets/images/logo.jpg" /> But if I view source in the browser, I can copy those urls that are created, paste them in the browser, and view the files that way. They just aren't being loaded. Some people mentioned earlier that it might be a .htaccess problem, here is my .htaccess: Code: RewriteEngine On Problem with base_url() and files not loading - El Forum - 03-29-2009 [eluser]TheFuzzy0ne[/eluser] First of all, this line is unnecessary: Code: RewriteCond $1 !^(index\.php|images|assets|css|js|robots\.txt) The two lines below it ensure that the rewrite rule only fires if the directory/file exists. I think that this may be the line that's causing the problem, as all requests will always be passed to index.php, because the request URI never starts with index.php, images, assets, css, js or robots.txt - They always start with "/beta". Good luck! Problem with base_url() and files not loading - El Forum - 04-07-2009 [eluser]jamaky[/eluser] I have similar problem with loading images. (application is on localhost and I use base_url() to create source path stored in database) While css file load correctly, images don't. I don't understand it. Images don't load correctly on first load of page (including background). But after 5-10 refershes, image is loaded. After clear browser cache and delete temporary internet files the problem is back. I don't understand why browser can't load image of size 88kB on first time. I have any problem with images yet. I tried to change .htaccess, config, and code. Without success. The source path is correct but image don't load (or load just partial). Here's my .htaccess file Code: RewriteEngine on Code: $config['base_url'] = "http://localhost/cres/"; Code: <link href=<?php echo '"'.base_url().'css/main.css"';?> rel="stylesheet" type="text/css"> Code: <link href="http://localhost/cres/css/main.css" rel="stylesheet" type="text/css"> 2. code generate Code: <img src="http://localhost/cres/images/general_figure/1.jpg" width="200" border="0"> 3. code generate Code: <img src="http://localhost/cres/images/coat_of_arms/1.png" width="200" border="0"> Both images are in these locations. Please help. Problem with base_url() and files not loading - El Forum - 04-07-2009 [eluser]TheFuzzy0ne[/eluser] I'm at my wits end with htaccess files, so I will post mine (which works for me), and hope you can make it work for you. Code: AddOutputFilterByType DEFLATE text/css text/html application/x-javascript application/javascript It was stolen from the [url="http://codeigniter.com/wiki/mod_rewrite/"]CodeIgniter wiki[/url], and has had various tweaks added onto it over time. Unfortunately, htaccess files seem to work differently from platform to platform. What works for me may not work for others. Problem with base_url() and files not loading - El Forum - 04-07-2009 [eluser]jedd[/eluser] What do your apache logs say? Quote:2. code generate Can you definitely load http://localhost/cres/images/general_figure/1.jpg and http://localhost/cres/images/coat_of_arms/1.png from your browser? |