8

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)

5
  • 1
    file path incorrect or file permission problem
    – JYoThI
    Sep 9, 2016 at 8:34
  • i have tried this in the separate folder, it working fine there. but when i am putting all these files into my view folder its giving the error in console
    – Priyanka
    Sep 9, 2016 at 8:38
  • show me your file structure
    – JYoThI
    Sep 9, 2016 at 8:41
  • Make sure you set your base_url in config.php
    – user4419336
    Sep 9, 2016 at 9:21
  • [This helped me a lot, you should have defined your css,images,js etc.(it is recommended) under any public folder. You can name it as assets/public... ](stackoverflow.com/questions/6630770/…)
    – Priyanka
    Sep 10, 2016 at 13:04

4 Answers 4

5

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/

8
  • i have given the relative path but it is still stucked on the same error.
    – Priyanka
    Sep 9, 2016 at 8:55
  • 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.
    – Tom
    Sep 9, 2016 at 8:56
  • 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/background.png</br>console is giving this..
    – Priyanka
    Sep 9, 2016 at 9:32
  • 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
    Sep 9, 2016 at 9:34
  • Yes, exactly. Take it out and put it in public or Codeigniter will not server it to the public.
    – Tom
    Sep 9, 2016 at 9:38
0

You can try replacing the contents of original 404 Page Not Found error page with your custom error page. Make sure you doesn't change the name of that file or its location.

Hope it helps

0

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

0

In my case problem was in incorrect file premissions (should be 644). In some cases is also smart to consider clearing cache in cloudflare.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.