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.

2
  • 1
    Have you set the base url in config.php $config['base_url'] = 'http://demo.example.com/' Commented Sep 17, 2017 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. Commented Sep 18, 2017 at 0:43

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

3 Comments

it was the stupid http that wolfgang said. Irritating! Thanks to you both.
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
in my situation the url helper functions link_tag fixed my issues

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.