base_url() and css -img-js |
[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: / My .htaccess looks like this, to hide the index.php/ from URL Code: RewriteEngine on 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> 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
[eluser]Clifford James[/eluser]
The easiest way is adding a / before the folder. Code: <link href="/css/style.css" rel="stylesheet" type="text/css" media="screen"> In this case there is no need for any rewrite in your .htaccess Without / www.example.com + css/style.css = www.example.com/css/style.css www.example.com/fu/bar + css/style.css = www.example.com/fu/bar/css/style.css With / www.example.com + /css/style.css = www.example.com/css/style.css www.example.com/fu/bar + /css/style.css = www.example.com/css/style.css
[eluser]Ngulo[/eluser]
really thanks sergius,really great work!!! now i've just started a project with the CSS ,IMG,and JS folders at same level of SYSTEM folder,keeping them by base_url()IMG/asd.gif for example,is not really a smart solution but is the way to make all works by default......later i will try your configuration,it seems to be really smarter!! bye
[eluser]Sergiu D[/eluser]
[quote author="Clifford James" date="1271011662"]The easiest way is adding a / before the folder. Code: <link href="/css/style.css" rel="stylesheet" type="text/css" media="screen"> In this case there is no need for any rewrite in your .htaccess Without / www.example.com + css/style.css = www.example.com/css/style.css www.example.com/fu/bar + css/style.css = www.example.com/fu/bar/css/style.css With / www.example.com + /css/style.css = www.example.com/css/style.css www.example.com/fu/bar + /css/style.css = www.example.com/css/style.css[/quote] Yes, this was the first thing that I've tried. But it's working only on projects where I have the web site in the root of my server. Else, I will have this: Code: / So, in this case, putting a "/" before every path, will throw me to the root, and of course, is nothing there.
[eluser]aminem9[/eluser]
I cross that you already have the solution here it is <link href="<?php echo base_url(); ?>/css/style.css" rel="stylesheet" type="text/css" media="screen">
[eluser]Sergiu D[/eluser]
[quote author="ispuk" date="1271011892"]really thanks sergius,really great work!!! now i've just started a project with the CSS ,IMG,and JS folders at same level of SYSTEM folder,keeping them by base_url()IMG/asd.gif for example,is not really a smart solution but is the way to make all works by default......later i will try your configuration,it seems to be really smarter!! bye [/quote] Glad I could help, ispuk. Let me know if you find this solution useful. I will go on with it, hope it will work for all time. That <base> tag really get me out of misery. )
[eluser]Ngulo[/eluser]
aminem9 you're right,and me is following your solution,but sometimes ,writing php also where it could be left,could save a lot of time , specially on big projects....you know so i really enjoy when some people trying new ways of working,to make all smarter they can
|
Welcome Guest, Not a member yet? Register Sign In |