1

IM trying to load some css directly within my view file, but its not working.

in my view file I have this.

<link href="<?php echo base_url(); ?>assets/css/core.css" rel="stylesheet" type="text/css" />

The assets folder is at the same level as Application

when I view source on the webpage it shows me this

demo.example.com/assets/css/core.css

but when i click the link to see if it's working the url becomes this...

http://demo.example.com/admin/demo.example.com/assets/css/core.css

not sure what I am doing wrong? Should I be adding something to my htaccess file?

Thanks in advance.

joeb
  • 777
  • 8
  • 28
  • 1
    Have you set the base url in config.php `$config['base_url'] = 'http://demo.example.com/'` –  Sep 17 '17 at 20:36
  • 1
    It is recommend now to set the base url in codeigniter 3 and up versions there is a comment above the base url which should read. –  Sep 18 '17 at 00:43

1 Answers1

1

You don't need to include the base_url() in your path because the webserver already knows your at www.example.com/admin and auto includes that.

Just use <link href="/assets/css/core.css" rel="stylesheet" type="text/css" />

Edit: Or actually you need to include the http: prefix on your base_url like wolfgang1983 said.

See this answer on CSS absolute and relative link paths. https://stackoverflow.com/a/17621358/3585500

ourmandave
  • 1,505
  • 2
  • 15
  • 49
  • 1
    it was the stupid http that wolfgang said. Irritating! Thanks to you both. – joeb Sep 17 '17 at 23:34
  • ugh, so now that i've added a sub path like, demo.example.com/admin the css breaks again. WTF am I doing wrong? apparantely its only a problem on chrome. Firefox works fine – joeb Sep 19 '17 at 23:43
  • in my situation the url helper functions `link_tag` fixed my issues – joeb Sep 22 '17 at 01:01