Welcome Guest, Not a member yet? Register   Sign In
base_url() and css -img-js
#11

[eluser]Sergiu D[/eluser]
Looks like I've found a workaround, after two days of searching. It's not the best solution and it's not the cleanest one, but at least it keeps my relative links working on a CodeIgniter project.

So, to start again, I have the following directory structure:

Code:
/
/system
/css
/scripts
/images
/template
.htaccess
index.php

My .htaccess looks like this, to hide the index.php/ from URL

Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|template|scripts|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]

Now, because I want to reference all my images, css or JS scripts with relative paths, I've found this HTML tag:

Code:
<base href="" target="">

It's a HTML 4.01 and XHTML 1.0 and 1.1 valid element. More information about it can be found at:
http://www.w3.org/TR/REC-html40/struct/l...tml#h-12.4
http://www.w3schools.com/TAGS/tag_base.asp

With CodeIgniter I've done somthing like this:

Code:
<html>
  <head>
    <title>TEST</title>
    <base href="<?php echo base_url(); ?>">

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

  <body>
    <img src="images/test.png" alt="">
    <a href="home/index/30/2">Link</a>
  &lt;/body&gt;
&lt;/html&gt;

And with this everything seem to work ok for now.

Anyway, if somebody know a better way to do it, I'm opened for any suggestion.
Thanks...

LATER EDIT:
Thank you, InsiteFX, seem like both of us came up with the same solution. Thanks Smile


Messages In This Thread
base_url() and css -img-js - by El Forum - 03-29-2010, 07:15 AM
base_url() and css -img-js - by El Forum - 03-29-2010, 07:20 AM
base_url() and css -img-js - by El Forum - 03-29-2010, 07:25 AM
base_url() and css -img-js - by El Forum - 03-29-2010, 07:26 AM
base_url() and css -img-js - by El Forum - 03-29-2010, 07:32 AM
base_url() and css -img-js - by El Forum - 03-29-2010, 07:38 AM
base_url() and css -img-js - by El Forum - 03-29-2010, 07:41 AM
base_url() and css -img-js - by El Forum - 04-11-2010, 06:38 AM
base_url() and css -img-js - by El Forum - 04-11-2010, 07:33 AM
base_url() and css -img-js - by El Forum - 04-11-2010, 07:40 AM
base_url() and css -img-js - by El Forum - 04-11-2010, 07:43 AM
base_url() and css -img-js - by El Forum - 04-11-2010, 07:47 AM
base_url() and css -img-js - by El Forum - 04-11-2010, 07:51 AM
base_url() and css -img-js - by El Forum - 04-11-2010, 07:55 AM
base_url() and css -img-js - by El Forum - 04-11-2010, 08:02 AM
base_url() and css -img-js - by El Forum - 04-11-2010, 08:06 AM
base_url() and css -img-js - by El Forum - 04-11-2010, 08:07 AM
base_url() and css -img-js - by El Forum - 04-11-2010, 08:11 AM



Theme © iAndrew 2016 - Forum software by © MyBB