GET 404 error for style.css not found

45,747

Solution 1

404 is a 'not found' error. Meaning, the browser cannot find your style.css with the path it was given. If it is working on some templates and not others, it is because you may have a different file structure for some templates, a sub-folder for example.

A quick fix would be to make your style.css load from an absolute path

https://yourdomain.com/public/css/style.css

A better solution would be to traverse the directory to the css folder and then reference your style.css.

Learn about relative paths and find a solution that works for all templates. The answer is likely to be something like:

/public/css/style.css

However, it could be something like:

../public/css/style.css

Where goes back to one more previous directory. More about absolute vs. relative paths http://www.coffeecup.com/help/articles/absolute-vs-relative-pathslinks/

Solution 2

Change <base href="/"> to <base href="./"> from index.html

Share:
45,747
Priyanka
Author by

Priyanka

Updated on November 01, 2020

Comments

  • Priyanka
    Priyanka over 3 years

    I am currently working on codeigniter framework, in the view i added my custom 404 error's page. But it is not loading the stylesheet from the folder errorpage/web/css/style.css. And i am getting an error in the browser's console GET : url/style.css 404(not found) (url is the address of my folder where my css file is)

  • Priyanka
    Priyanka over 7 years
    i have given the relative path but it is still stucked on the same error.
  • Tom
    Tom over 7 years
    try the absolute path. Your relative path is probably wrong. If you use the absolute path and it works, you then know that is definitely the problem. For further help, post your file structure and the absolute path for your style.css that the browser constructs from the relative path.
  • Priyanka
    Priyanka over 7 years
    I am working locally, on giving absolute path <br>Not allowed to load local resource: file:///C:/xampp/htdocs/website/application/views/errorpage/‌​web/images/backgroun‌​d.png</br>console is giving this..
  • Tom
    Tom over 7 years
    Yeah of course it will give that error if your try load an image from that directory, load images from a public directory that sits outside of your /application folder. Codeigniter protects files that sit inside /application, keeping them away from the public.
  • Tom
    Tom over 7 years
    Yes, exactly. Take it out and put it in public or Codeigniter will not server it to the public.
  • Priyanka
    Priyanka over 7 years
    Is there any way to fix this problem with .htaccess file?
  • Tom
    Tom over 7 years
    No. Take the public assets and put them in a publicly accessible directory.
  • Priyanka
    Priyanka over 7 years
    Thanks a lot Tom, it helped me.